Search code examples
sqlvb.netcom

VB SQL error: The instruction INSERT contains a syntax error


I'm woking on a project with a database, and I'm trying to create a row in my table, using the following query:

"INSERT INTO USERCOINFO (username, company, streetAddress, postalCode, language, department, postOfficeBox, country, telephoneNumber, faxNumber, title, givenName, surname) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"

the values are filled by the following variables using

Dim dbInsert As New OleDb.OleDbCommand
Dim objClient = GetObject(objRecordSet.Fields("ADsPath").Value)

Dim username = objRecordSet.Fields("Name").Value
Dim company = objClient.company
Dim streetAddress = objClient.streetAddress
Dim postalCode = objClient.postalCode
Dim lo = objClient.lo
Dim department = objClient.department
Dim postOfficeBox = objClient.postOfficeBox
Dim country = objClient.co
Dim telephoneNumber = objClient.telephoneNumber
Dim faxNumber = objClient.facsimiletelephonenumber
Dim title = objClient.title
Dim givenName = objClient.givenName
Dim surname = objClient.sn

and then I bind them with:

dbInsert.Parameters.AddWithValue("@p1", username)
dbInsert.Parameters.AddWithValue("@p2", company)
'and so on...

to my knownlege, this is correct, but it still returns a syntax error: The instruction INSERT contains a syntax error.


Solution

  • as stated in the comments and suggested by Jim Hewitt, it was indeed the usuage of a syntax word in the column declaration in the statement, I've changed the column name to something else to further reduce confusion from language to CoLanguage. everything is now working.

    thanks to all the people who were willing to help be with this.

    Meep, Luuk