Results 1 to 2 of 2

Thread: SQL Problem - INSERT INTO [RESOLVED]

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2002
    Location
    The Twilight Zone
    Posts
    295

    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()
    Last edited by modernthinker; Aug 26th, 2005 at 08:13 PM.

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2002
    Location
    The Twilight Zone
    Posts
    295

    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)";

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width