I am trying to insert data into an MS Access DB through a VB.net Windows Forms App
when executing this code
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")
i get this error message -
System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement
Please Help
Thanks, Jacob
CodePudding user response:
You insert every value as text which probably is not the case. Adjust that, for example for the port number:
.. VALUES (" & nudPortNumber.Value & ", ..
CodePudding user response:
Add a close parenthesis, )
, at the end of your VALUES
clause like this:
& chPOE.Checked & "')", con)