SQL Problem - INSERT INTO [RESOLVED]
I haven't got a clue why this isn't working, its a simple SQL insert into statement.
my code:
Code:
private void Page_Load(object sender, System.EventArgs e)
{
OleDbConnection WO_Conn = new OleDbConnection(ConfigurationSettings.AppSettings["DSN"]);
string SQL;
SQL = "INSERT INTO LoginDetails (UserID, Username, Password) VALUES (@UseriD, @Username, @Password)";
OleDbCommand WO_Cmd2 = new OleDbCommand(SQL, WO_Conn);
WO_Cmd2.Parameters.Add("@UserID", "6789");
WO_Cmd2.Parameters.Add("@Username", "hello");
WO_Cmd2.Parameters.Add("@Password", "world");
WO_Conn.Open();
WO_Cmd2.ExecuteNonQuery();
WO_Conn.Close();
}
error message is:
Code:
System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.
Stack trace:
Code:
[OleDbException (0x80040e14): Syntax error in INSERT INTO statement.]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr)
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
WiseOwls.insertTEST.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\test\insert.aspx.cs:36
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
Re: SQL Problem - INSERT INTO
Problem solved!
Password is a reserved Keyword in MsAccess. You need to enclose the word Password using [] as in [Password].
So the SQL should read:
INSERT INTO LoginDetails (UserID, Username, [Password]) VALUES (@UseriD, @Username, @Password)";