SQL error: Incorrect syntax near the keyword 'User'

前端 未结 4 659
滥情空心
滥情空心 2020-11-27 07:04

I am using SQL to insert data to SQL Database file using C# as follows.

    String cs = System.Configuration.ConfigurationManager.ConnectionStrings[\"connect         


        
相关标签:
4条回答
  • 2020-11-27 07:34

    User is a sql reserved keyword. Enclosing it in square brackets should solve this. E.g INSERT INTO [User]

    easily showing that you need brackets around it like so: [User]

    0 讨论(0)
  • 2020-11-27 07:42

    User is a t-sql reserved keyword. Enclosing it in square brackets should solve this. E.g INSERT INTO [User]

    0 讨论(0)
  • 2020-11-27 07:43

    User is a reserved keyword, so you must use square brackets to make it explicit that you mean the object named "User" it, i.e. use [User] instead of User.

    0 讨论(0)
  • 2020-11-27 07:49

    run your query against the database. You can use the declare sql keyword to define your variables and give them values. If you need to figure out the variables values, set a breakpoint at conn.Open and then use the locals window to see what values you are passing in. Another tool at your disposal is the Sql Profiler. You can start a trace then run your program. You should be able to see the query as executed in the profile after the code you have posted has run.

    All of this should help you to figure out what is wrong with your sql when the exception does not provide enough information.

    The Sql Server Management Studio should have highlighted the User keyword in your sql statement, easily showing that you need brackets around it like so: [User]

    0 讨论(0)
提交回复
热议问题