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','email@example.com','firstname.lastname@example.org','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 by mike_2000_17: Fixed formatting