Search code examples
c#sqldatabasems-accessoledb

Error With Dynamically Created SQL Insert statement


May I know what's wrong with my statement? I receive a syntax error. Been trying to find out what's wrong all day. :(

cmd.CommandText = "INSERT INTO LogIn(Username,Password) VALUES('" + AddUsernameTextBox.Text + "','" + AddPasswordTextBox.Text + "')";

Solution

  • cmd.CommandText = "INSERT INTO LogIn([Username],[Password]) VALUES('" + AddUsernameTextBox.Text + "','" + AddPasswordTextBox.Text + "')";
    

    This code will help if the error is due to reserved keywords :- username and password. Please quote the error if this is not the case .