private void Button1_Click(object sender, System.EventArgs e)
{
string editId = Request["New_Id"].ToString();
string tTitle = this.TextBox1.Text.ToString();
string tClass = this.TextBox2.Text.ToString();
string tContent = this.TextBox3.Text.ToString();
string tAuthor = this.TextBox4.Text.ToString();
SqlConnection updateCon = Db.CreateCon();
updateCon.Open();
SqlCommand updateCmd = new SqlCommand ("update News_List set (News_Title,News_Class,News_Content,News_Author) = ('"+tTitle+"','+tClass+','tContent','+tAuthor+') where New_Id='"+editId+"'",updateCon);
updateCmd.ExecuteNonQuery();
Response.Write("<script language='javascript'>alert('修改成功');</script>");
}
但是老是报错。好象不能批修改,麻烦大侠们帮我看看 我菜鸟

解决方案 »

  1.   

    SQl語句寫錯了!
    private void Button1_Click(object sender, System.EventArgs e)
    {
    string editId = Request["New_Id"].ToString();
    string tTitle = this.TextBox1.Text.ToString();
    string tClass = this.TextBox2.Text.ToString();
    string tContent = this.TextBox3.Text.ToString();
    string tAuthor = this.TextBox4.Text.ToString();
    SqlConnection updateCon = Db.CreateCon();
    updateCon.Open();
    SqlCommand updateCmd = new SqlCommand ("update News_List set News_Title= '"+tTitle+"',News_Class = '"+tClass+"',News_Content = '"+tContent"',News_Author = '"+tAuthor+"' where New_Id='"+editId+"'",updateCon);
    updateCmd.ExecuteNonQuery();
    Response.Write("<script language='javascript'>alert('修改成功');</script>");
    }
      

  2.   

    看看这个语句最后出来啥个结果:
    ("update News_List set (News_Title,News_Class,News_Content,News_Author) = ('"+tTitle+"','+tClass+','tContent','+tAuthor+') where New_Id='"+editId+"'"自己认真核对下少了多少个双引号?新手也不能这么不认真吧!
      

  3.   

    必须是这样'"+val+"' val表示变量
      

  4.   

    设个断点,跟踪sql语句,看看sql语句是什么内容