I am trying to insert data from my VB 2008 program into an MS Access Database. My code is as follows:

insertSQL = "INSERT INTO ExamInstance (SiteLocation, SiteTime, Student_SEmail, Proctor_PEmail, Exam_CourseNumber, Username, Password) VALUES ('" & SiteLocation & "','" & SiteTime & "','" & SEmail & "','" & PEmail & "','" & CourseNumber & "','" & UserName & "','" & Password & "');"

objOleDbCommand.Connection.Open()

objOleDbCommand.CommandText = insertSQL
objOleDbCommand.ExecuteNonQuery()

objOleDbCommand.Connection.Close()

My variables all have string values. When I outputted the value of 'insertSQL' to a MsgBox I get the output:

INSERT INTO ExamInstance (SiteLocation, SiteTime, Student_SEmail,Proctor_PEmail, Exam_CourseNumber, Username, Password) VALUES ('testLocation','02/02/2009 03:32 PM','tests@email.com','testp@email.com','Equine_Massage','NBCAAM3254','9389801');

When I attempt to inject this from the Access SQL Query View it works just fine. But when I try to pass it with my code I get the following error:

OleDbException was unhandled

Syntax error in INSERT INTO statement.

It's such a vague error that I can't seem to figure it out.

It's not a problem with the OleDbConnection as I run other queries on the same connection just fine.

Any help would be greatly appreciated.

I figured it out. It was having problems with the column name 'Password'. I changed the column name to 'Pass' and everything worked out fine.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.