我正在尝试写这一行:
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'.
答案 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);