running a vb application with the following code. I keep getting an error on my ‘INSERT INTO’ sql query, can anyone see what im doing wrong? This is the error – Syntax error in INSERT INTO statement.
connetionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source = C:\Users\Dave\Documents\joblist.mdb;"
connection = New OleDb.OleDbConnection(connetionString)
Sql = "INSERT INTO jobList (StaffID, staffName, staffLastName, note, fault, section, techID, jobcomplete) VALUES ('" & staffid & "','" & staffFN & "','" & staffLN & "','" & staffNotes & "','" & staffFault & "', '" & staffSection & "', '" & techId & "','" & ava & "')"
connection.Open()
oledbAdapter.UpdateCommand = connection.CreateCommand
oledbAdapter.UpdateCommand.CommandText = Sql
oledbAdapter.UpdateCommand.ExecuteNonQuery()
connection.Close()
Me.JobListTableAdapter.Fill(Me.JoblistDataSet2.jobList)
NoteandSectionare reserved words in Jet SQLYou need to encapsulate them with square brackets
This is the source of you syntax error, but …..
aside from that, you have many problems here:
insert command.
leads to sql injection attacks and problems in correct parsing of text
(apostrophes, invalid dates, invalid numbers, etc)
staffIDandtechIDseems to be numeric fields in the database, butyou put their values inside single quotes like strings. If they are
numerics you will get another possible error there.