Reputation:
I have two table , User and UserReputation . I want to get data with SqlDataAdapter.
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=abc.com;Integrated Security=True");
SqlDataAdapter userDataAdapter = new SqlDataAdapter("SELECT * FROM User", conn);
SqlDataAdapter userReputationDataAdapter = new SqlDataAdapter("SELECT * FROM UserReputation", conn);
DataSet ds = new DataSet();
userDataAdapter.Fill(ds, "User");
userReputationDataAdapter.Fill(ds, "UserReputation");
I tested the connection string and connection.There is no problem.But I got below error at the userDataAdapter.Fill(ds, "User");
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: Incorrect syntax near the keyword 'User'.
Thanks for your help
Upvotes: 1
Views: 1651
Reputation: 7696
Change your query to the following:
"SELECT * FROM [User]"
User
is a keyword, if you have Table
named "User" you should use brackets
or as @Rahul has mentioned you can also use ""
:
"SELECT * FROM \"User\""
Upvotes: 3