C#修改数据的时候'(' 附近有语法错误。
privatevoidbutton7_Click(objectsender,EventArgse){SqlConnectioncon=newSqlConnection()...
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="'(' 附近有语法错误。"
帮忙写出正确的运行方式!并指出错之处!谢谢~ 展开
{
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="'(' 附近有语法错误。"
帮忙写出正确的运行方式!并指出错之处!谢谢~ 展开
6个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询