Incorrect syntax near the keyword 'User'

前端 未结 2 1745
春和景丽
春和景丽 2020-12-11 23:42

The error is:

An unhandled exception of type \'System.Data.SqlClient.SqlException\' occurred in System.Data.dll
Additional information: Incorrec

2条回答
  •  情歌与酒
    2020-12-12 00:05

    "User" is a reserved word in SQL Server, so you have to use a delimited identifier to refer to your table. Try

    SqlCommand command4 = new SqlCommand("SELECT * FROM [User]", conn);
    

    instead... or rename the table to something which isn't reserved.

    (I'd also strongly advise you to keep the data access out of your UI code, dispose of connections properly etc... but that's a different matter.)

提交回复
热议问题