本文介绍了我在c#中的executenonquery()上遇到语法错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在数据库中输入了一些值。我在插入语法中没有任何错误,但它在ExecutenonQuery()函数上显示语法错误。
我尝试过:
这是我的代码。
I am entering some values into the database. I know nothing wrong in the "insert into syntax", but it is showing syntax error on the ExecutenonQuery() function.
What I have tried:
Here is my code.
connection.Open();
pictureBox12.Visible = true;
string sql = "insert into Pass (Sno,pdate, Relay Off Coil Voltage, Regulator Input Voltage, Relay 1 ON, Relay 1 OFF, Relay 2 ON, Relay 2 OFF, Regulator Output Voltage, MCLR Voltage, Input Voltage Sense, Current Sense, Trimpot Value, Fail Case No) values (" + int.Parse(label2.Text) + ",'"+ DateTime.Now.Date.ToShortDateString()+"'," + float.Parse(label6.Text) + "," + float.Parse(label7.Text) + "," + int.Parse(label19.Text) + "," + int.Parse(label20.Text) + "," + int.Parse(label21.Text) + "," + int.Parse(label22.Text) + "," + float.Parse(label23.Text) + "," + float.Parse(label24.Text) + "," + float.Parse(label25.Text) + "," + float.Parse(label26.Text) + "," + float.Parse(label27.Text) + ",1)";
OleDbCommand cmd = new OleDbCommand(sql, connection);
cmd.ExecuteNonQuery();
connection.Close();
推荐答案
string sql = "insert into Pass (Sno,pdate, [Relay Off Coil Voltage], [Regulator Input Voltage], [Relay 1 ON], [Relay 1 OFF], [Relay 2 ON], [Relay 2 OFF], [Regulator Output Voltage], [MCLR Voltage], [Input Voltage Sense], [Current Sense], [Trimpot Value],[Fail Case No])....
你需要用一对方括号包装这样的列名。
如果您有更多问题,请告诉我。
谢谢:)
You need to wrap such column name with a pair of square braces.
Please let me know, if you have more questions.
Thanks :)
这篇关于我在c#中的executenonquery()上遇到语法错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!