insert into 语句中的语法错误 - VB.NET

Syntax error in insert into statement - in VB.NET

我正在尝试使用以下代码将记录插入 MS Access 数据库。我在我的项目中多次使用相同类型的代码。但是不知道为什么会报错,说是语法错误。有人请告诉我代码哪里错了。

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(?,?,?,?,?,?,?)"
`cmdText = "insert into tblBottling([bottlingDate],[workerName],[seed],[size],[noOfBottles],[timeTaken],[remarks]) values(?,?,?,?,?,?,?)"

Please always use square brackets for your columns incase of such error.

Because you cannot memorise all the keywords.

Good Luck