ExecuteNonQuery() throws “Incorrect syntax near the keyword 'User'”

前端 未结 2 614
野性不改
野性不改 2021-01-24 21:06

I started learning C# last week and I\'m now having trouble with an INSERT sql statement. I used the following code, then I tell you what happens.

private void A         


        
相关标签:
2条回答
  • 2021-01-24 21:46

    You've got a table with the name "User", but that's a reserved keyword.

    You could rename the table, or enclose it in brackets when you reference it:

    string commandText = "INSERT INTO [User] (firstName ...
    
    0 讨论(0)
  • 2021-01-24 21:47

    Change the table name from "User" to something else because User is a reserved keyword that cannot be used again, so if you use any other name for table the code will work fine example:-

    create table User1(firstName varchar(20),lastName varchar(20),adress varchar(20),town varchar(20),favoriteCurrency int)
    
    0 讨论(0)
提交回复
热议问题