Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在VB.NET中的insert into语句中出现语法错误_Vb.net_Oledbcommand - Fatal编程技术网

在VB.NET中的insert into语句中出现语法错误

在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

我正试图用下面的代码将一条记录插入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(?,?,?,?,?,?,?)"

Size是MS Access的保留关键字。如果您想将该单词用作列名,则应始终将其括在方括号内

cmdText = "insert into tblBottling
          (bottlingDate,workerName,seed,[size],noOfBottles,timeTaken,remarks) 
          values(?,?,?,?,?,?,?)"
请始终在列中使用方括号,以防出现此类错误

因为你不能记住所有的关键词

祝你好运

请始终在列中使用方括号,以防出现此类错误

因为你不能记住所有的关键词

祝你好运