C#修改数据的时候'(' 附近有语法错误。

private void button7_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=.;Initial Catalog=STU_student;Integrated Security=True";
//string sql = "update StudentDetails set(Snum='" + this.textBox20.Text.Trim() + "',Sname='" + this.textBox19.Text + "',Ssex='" + this.textBox18.Text + "',Sage='" + this.textBox14.Text + "',Sdept='" + this.textBox17.Text + "',class='" + this.textBox16.Text + "',math='" + this.textBox15.Text + "',english='" + this.textBox13.Text + "',banzhang='" + 0 + "')";
string sql = "update StudentDetails set('" + this.textBox20.Text.Trim() + "','" + this.textBox19.Text + "','" + this.textBox18.Text + "','" + this.textBox14.Text + "','" + this.textBox17.Text + "','" + this.textBox16.Text + "','" + this.textBox15.Text + "','" + this.textBox13.Text + "','" + 0 + "')";

con.Open();
SqlCommand cmd = new SqlCommand(sql, con);
int i = cmd.ExecuteNonQuery();

if (i == 1)
{
MessageBox.Show("更新成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

}
con.Close();

}
运行后,到修改数据阶段出现 '(' 附近有语法错误。
未处理 System.Data.SqlClient.SqlException
Message="'(' 附近有语法错误。"
帮忙写出正确的运行方式!并指出错之处!谢谢~

第1个回答  2010-06-10
你的update语句有问题,像这样update table set column1='context' where column2=2
第2个回答  2010-06-10
update StudentDetails set Snum='" + this.textBox20.Text.Trim() + "',Sname='" + this.textBox19.Text + "',Ssex='" + this.textBox18.Text ..........
不需要括号啊本回答被提问者采纳
第3个回答  2010-06-10
设断点 看sql语句是否正确.
第4个回答  2010-06-10
把string sql里的一对括号去掉。
第5个回答  2010-06-12
sql语句拼的有问题啊