Syntax error in INSERT INTO statement in asp.net

前端 未结 2 1248
南旧
南旧 2021-01-26 09:37

I am using ASP.NET with MS.Access In databse.. there is table called login with three fields i.e. id, username, password. following is the code which i am trying to run.

相关标签:
2条回答
  • 2021-01-26 10:29

    try like this

    String q = "insert into login (username, [password]) values (@u, @p)"; 
    

    cause: password is reserved word

    Source

    0 讨论(0)
  • 2021-01-26 10:35

    try this

    String username = TextBox1.Text;
    String password = TextBox2.Text;
    OleDbConnection dbConnection = new OleDbConnection("provider=microsoft.ACE.OLEDB.12.0; Data source=C:\\Users\\Mohit Kumar Singla\\Documents\\phonebook.accdb");
    dbConnection.Open();
    
    Console.WriteLine("Error Occurred. Please check");
    System.Diagnostics.Debug.WriteLine("Error--------------------------------");
    
    String q = "insert into login (username, [password]) values (@u, @p)";               
    OleDbCommand cmd = new OleDbCommand(q, dbConnection);
    
    cmd.Parameters.AddWithValue("@u", username);
    cmd.Parameters.AddWithValue("@p", password);
    
    cmd.ExecuteNonQuery();
    dbConnection.Close();
    
    0 讨论(0)
提交回复
热议问题