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.CommandText = insertSQL


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.

Edited 4 Years Ago by mike_2000_17: Fixed formatting

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.

This question has already been answered. Start a new discussion instead.