SQL中的语法不正确用户'

时间:2014-10-01 20:41:07

标签: c# sql sql-server sqlcommand

我正在尝试写这一行:

SqlCommand MySqlCommand = new SqlCommand(@
   "INSERT INTO User(NAME ,PASSWORD,PUBLISH_FOLDER,ACTIVE,IP,PORT)
            Values ('shula','Aa1234','study','true','1015','8080')"
           , MyConnection);

我得到的例外是:

incorrect syntax near the keybord 'User'.

2 个答案:

答案 0 :(得分:6)

User是MS Sql-Server中的reserved keyword,您必须使用方括号[]隐藏它:

INSERT INTO [User](NAME ,PASSWORD ,PUBLISH_FOLDER,ACTIVE,IP,PORT) Values ('shula','Aa1234','study','true','1015','8080')

但是不要创建这样的表:Creating table names that are reserved words/keywords in MS SQL Server

答案 1 :(得分:2)

尝试围绕"用户"方括号:

SqlCommand MySqlCommand = new SqlCommand("INSERT INTO [User](NAME ,PASSWORD ,PUBLISH_FOLDER,ACTIVE,IP,PORT) Values ('shula','Aa1234','study','true','1015','8080')", MyConnection);