查询错误“INSERT中的语法错误”

时间:2014-11-13 11:26:34

标签: vb.net

似乎我总是有错误"syntax error in INSERT into"。你能告诉我为什么吗?

Dim conn As New System.Data.OleDb.OleDbConnection()
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Bro_Proj.accdb"
conn.Open()
Dim sql As String = "INSERT INTO Order(Stud_ID, BookName, Quantity, sale, DateOfOrder, TimeOfOrder)  VALUES ('" & TextBox1.Text & "', '" & ComboBox3.Text & "', '" & NumericUpDown1.Value & "','" & TextBox10.Text & "',' " & TextBox8.Text & "','" & TextBox9.Text & "') ;"
Dim sqlc As New System.Data.OleDb.OleDbCommand(sql, conn)
sqlc.ExecuteNonQuery()
conn.Close()

1 个答案:

答案 0 :(得分:-1)

Quantity Data类型是Integer,因此您必须删除qyantity参数中的简单引号,真正的代码如下:

Dim sql As String = "INSERT INTO Order(Stud_ID, BookName, Quantity, sale, DateOfOrder, TimeOfOrder)  
VALUES ('" & TextBox1.Text & "', '" & ComboBox3.Text & "', " & NumericUpDown1.Value & ",'" & TextBox10.Text & "',' " & TextBox8.Text & "','" & TextBox9.Text & "')"