0

I'm trying to write this line:

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

The exception i get is:

incorrect syntax near the keybord 'User'.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Try putting a space after `USER` in your insert command. Also, please verify that the error message is exactly as it in the question. You appear to have misspellings, which will make it difficult for other people with a similar problem to find your question. – mason Oct 01 '14 at 20:43

2 Answers2

7

User is a reserved keyword in MS Sql-Server, you have to escape it with square brackets []:

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

But do not create such tables: Creating table names that are reserved words/keywords in MS SQL Server

Community
  • 1
  • 1
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
2

Try surrounding "User" with square brackets:

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