在VB.NET中的insert into语句中出现语法错误
我正试图用下面的代码将一条记录插入MS Access数据库。我在我的项目中多次使用相同类型的代码。但是我不知道为什么会出错,说是语法错误。有人请告诉我代码哪里错了在VB.NET中的insert into语句中出现语法错误,vb.net,oledbcommand,Vb.net,Oledbcommand,我正试图用下面的代码将一条记录插入MS Access数据库。我在我的项目中多次使用相同类型的代码。但是我不知道为什么会出错,说是语法错误。有人请告诉我代码哪里错了 Try If MainForm.con.State = ConnectionState.Closed Then MainForm.con.Open() End If Dim cmdText As St
Try
If MainForm.con.State = ConnectionState.Closed Then
MainForm.con.Open()
End If
Dim cmdText As String
cmdText = "insert into tblBottling(bottlingDate,workerName,seed,size,noOfBottles,timeTaken,remarks) values(?,?,?,?,?,?,?)"
Dim command As OleDbCommand = New OleDbCommand(cmdText, MainForm.con)
command.Parameters.AddWithValue("@bottlingDate", botDate.Value.ToString("dd-MM-yy"))
command.Parameters.AddWithValue("@workerName", workerCB.SelectedItem.ToString)
command.Parameters.AddWithValue("@seed", seedCB.SelectedItem.ToString)
command.Parameters.AddWithValue("@size", botSizeCB.SelectedItem.ToString)
command.Parameters.AddWithValue("@noOfBottles", CInt(noOfBot.Text))
command.Parameters.AddWithValue("@timeTaken", timeTakenTxt.Text)
command.Parameters.AddWithValue("@remarks", remarksTxt.Text)
command.ExecuteNonQuery()
MainForm.con.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Size是MS Access的保留关键字。如果您想将该单词用作列名,则应始终将其括在方括号内
cmdText = "insert into tblBottling
(bottlingDate,workerName,seed,[size],noOfBottles,timeTaken,remarks)
values(?,?,?,?,?,?,?)"
Size是MS Access的保留关键字。如果您想将该单词用作列名,则应始终将其括在方括号内
cmdText = "insert into tblBottling
(bottlingDate,workerName,seed,[size],noOfBottles,timeTaken,remarks)
values(?,?,?,?,?,?,?)"
请始终在列中使用方括号,以防出现此类错误
因为你不能记住所有的关键词
祝你好运
请始终在列中使用方括号,以防出现此类错误
因为你不能记住所有的关键词
祝你好运