winforms ERROR -INSERT INTO语句中存在语法错误

z5btuh9x  于 2022-11-16  发布在  其他
关注(0)|答案(1)|浏览(151)

我正在尝试通过www.example.com Windows窗体应用程序将数据插入MS Access数据库VB.net
执行此代码时

Dim con As New OleDbConnection(CS)
            Dim cmd As New OleDbCommand("INSERT INTO Ports ([PortNumber] , [DistributionBoardLocation] , [DistributionBoardSubLocation] , [PortLocation] , [PortSubLocation] , [PortDevice] , [POE]) VALUES('" & nudPortNumber.Value & "', '" & txtDBLocation.Text & "', '" & txtDBSubLocation.Text & "' , '" & txtPortLocation.Text & "' , '" & txtPortSubLocation.Text & "' , '" & txtPortDevice.Text & "' , '" & chPOE.Checked & "'", con)

            con.Open()
                cmd.ExecuteNonQuery()
                con.Close()

                MsgBox("New Port Has Been Created")

我收到此错误消息-

System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement

请帮帮忙
谢谢你,雅各布

xzlaal3s

xzlaal3s1#

您将每个值都作为文本插入,但实际情况可能并非如此。请进行调整,例如端口号:

.. VALUES (" & nudPortNumber.Value & ", ..

相关问题