string sqlConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
    
    protected void Page_Load(object sender, EventArgs e)
    {
        int typeid = int.Parse(Request["id"].ToString());
        using (SqlConnection con = new SqlConnection(sqlConnString)) 
        {
            SqlCommand cmd = con.CreateCommand();
            cmd.CommandText = "Select * from type where typeid=" + typeid;
            con.Open();
            SqlDataReader ds = cmd.ExecuteReader();
            if (ds.Read())
            {
                TextBox1.Text = ds["type"].ToString();
                txtTitle.Text = ds["note"].ToString();
            }
            ds.Close();
            con.Close();
        } 
    }
    protected void Button2_Click(object sender, ImageClickEventArgs e)
    {
        int typeid = int.Parse(Request["id"].ToString());
        SqlConnection con = new SqlConnection(sqlConnString);
        SqlCommand cmd1 = con.CreateCommand();
        string type = this.TextBox1.Text;
        string note = this.txtTitle.Text;
        cmd1.CommandText = "update type set type='"+type+"',note='"+note+"' where typeid=" + typeid;
        con.Open();
        int sdr = cmd1.ExecuteNonQuery();
        if (sdr == 0)
        {
            ScriptManager.RegisterStartupScript(Button2, this.GetType(), "Button2", "alert('更新大类失败!');", true);
        }        else
        {
            ScriptManager.RegisterStartupScript(Button2, this.GetType(), "Button2", "alert('更新大类成功!');", true);
            this.TextBox1.Text = string.Empty;
            this.txtTitle.Text = string.Empty;
        }
        con.Close();
    }
不知道是不是少了什么关键的东西,我更新是成功的,但是数据不变,断点cmd1.CommandText = "update type set type='"+type+"',note='"+note+"' where typeid=" + typeid;
commandText=""  请高手看看我哪里搞错了

解决方案 »

  1.   

    cmd1.CommandText = "update type set type='"+type+"',note='"+note+"' where typeid=" + typeid;
    你有没有放复制到数据库中试试啊?我试了试,type是关键字,列名和表名相同不会冲突吧!
      

  2.   

    我把'"+type+"'写成'type' 是没问题的
      

  3.   

    呵呵!慢慢来!你起名字时最好别起关键字!你用Parameter传值试试吧!你写的那样sql语句,我早不用了,就怕糊涂了!
      

  4.   

    @type 我也试过了 可能是因为上面那个传回信息的原因
      

  5.   

    你这没报错 那肯定是你SQL语句出问题了
    你这样 
    cmd1.CommandText = "update type set type='"+type+"',note='"+note+"' where typeid=" + typeid;
    在这一句打上断点。。 看看拼接的SQL语句是否正确 然后将SQL语句复制到数据库去跑 再具体分析一下