I worked on MYSQL with ASP.NET. Just today started to try SQL commands in MSAccess. I tried the following code for which I am getting an unhandeled exception error. Anybody please check the below and let me know where the error is at.
string ConnStr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\project\Pages\db.mdb";
OleDbConnection MyConn = new OleDbConnection(ConnStr);
OleDbCommand cmd = new OleDbCommand();
cmd = new OleDbCommand("INSERT INTO accounts(email, password)VALUES(?, ?)", MyConn);
cmd.Parameters.Add("email", OleDbType.VarChar).Value = "val1";
cmd.Parameters.Add("password", OleDbType.VarChar).Value = "val2";
MyConn.Open();
cmd.ExecuteNonQuery();
MyConn.Close();
I created an Access database with a table accounts and field ID, email and password.
The exact error I am getting is (but I believe that my syntax is correct)
Syntax error in INSERT INTO statement.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.
Source Error:
Line 22: cmd.Parameters.Add("password", OleDbType.VarChar).Value = "val2";
Line 23: MyConn.Open();
Line 24: cmd.ExecuteNonQuery();
Line 25: MyConn.Close();
Line 26: }
“Password” is a reserved word. Put it inside brackets.
http://support.microsoft.com/kb/321266