Home >Database >Mysql Tutorial >SQL Error 'Incorrect syntax near 'User'': How to Fix INSERT Statements?
When attempting to insert data into a SQL database using C#, you may encounter the following error:
Incorrect syntax near the keyword 'User': INSERT INTO User (login, password, status) VALUES (@login, @password, @status)
This error arises because "User" is a reserved keyword in SQL. To resolve this issue, you must enclose the table name in square brackets, explicitly indicating that it refers to an object and not the keyword.
Here's the modified code with the correction:
String sql = "INSERT INTO [User] (login, password, status) " + "VALUES (@login, @password, @status)";
By enclosing "User" in square brackets, you are explicitly specifying that you are referring to the table named "User" and not attempting to use the keyword "User" in your query. This correction should resolve the syntax error and allow you to successfully insert data into your database.
The above is the detailed content of SQL Error 'Incorrect syntax near 'User'': How to Fix INSERT Statements?. For more information, please follow other related articles on the PHP Chinese website!