C#编程中要怎么处理错误Incorrect syntax near the keyword 'insert'.Incorrect syntax near ''. 5
sql2="insertintoPerson(ID,name,sex,place,level,specialty,work,department,busi";sql3="...
sql2 = "insert into Person ( ID,name,sex,place,level,specialty,work,department,busi";
sql3 = "values('" + textBox1.Text.ToString() + "','" + textBox2.Text.ToString() + "','" + comboBox1.Text.
ToString() + "','" + textBox3.Text.ToString() + "','" + textBox5.Text.
ToString() + "','" + textBox6.Text.ToString() + "','" + textBox7.Text.ToString() + "','" + textBox8.Text.
ToString() + "','" + textBox9.Text.ToString() + "'"
sql1 = sql2 + ")" + sql3 + ")";
cmd.CommandText = sql1;
cmd.ExecuteNonQuery();
在执行的时候系统提示错误Incorrect syntax near the keyword 'insert'.
Incorrect syntax near ''.,要怎么处理这个错误呢? 展开
sql3 = "values('" + textBox1.Text.ToString() + "','" + textBox2.Text.ToString() + "','" + comboBox1.Text.
ToString() + "','" + textBox3.Text.ToString() + "','" + textBox5.Text.
ToString() + "','" + textBox6.Text.ToString() + "','" + textBox7.Text.ToString() + "','" + textBox8.Text.
ToString() + "','" + textBox9.Text.ToString() + "'"
sql1 = sql2 + ")" + sql3 + ")";
cmd.CommandText = sql1;
cmd.ExecuteNonQuery();
在执行的时候系统提示错误Incorrect syntax near the keyword 'insert'.
Incorrect syntax near ''.,要怎么处理这个错误呢? 展开
3个回答
展开全部
你的sql2有问题(字段数据类型,你自已注意一下。如果有数值型的,就要用'小分号) :
改成以下的试试:
sql2 = "insert into Person ( name,sex,place,level,specialty,work,department,busi";
sql3 = " values('" + textBox1.Text.ToString() + "','" + textBox2.Text.ToString() + "','" + comboBox1.Text.
ToString() + "','" + textBox3.Text.ToString() + "','" + textBox5.Text.
ToString() + "','" + textBox6.Text.ToString() + "','" + textBox7.Text.ToString() + "','" + textBox8.Text.
ToString() + "','" + textBox9.Text.ToString() + "'"
另外那个ID,在数据库中要改为自动增加。
改成以下的试试:
sql2 = "insert into Person ( name,sex,place,level,specialty,work,department,busi";
sql3 = " values('" + textBox1.Text.ToString() + "','" + textBox2.Text.ToString() + "','" + comboBox1.Text.
ToString() + "','" + textBox3.Text.ToString() + "','" + textBox5.Text.
ToString() + "','" + textBox6.Text.ToString() + "','" + textBox7.Text.ToString() + "','" + textBox8.Text.
ToString() + "','" + textBox9.Text.ToString() + "'"
另外那个ID,在数据库中要改为自动增加。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询