Reputation: 71
I'm trying to do what the title said but I get this error at runtime:
Incorrect syntax near the keyword 'Top'.
string connString = @"server =.\sqlexpress; Database=BestScores.mdf; trusted_connection=TRUE; AttachDbFileName= D:\Programing\Projects Visual Studio 2008\JigSaw\JigSaw\bin\Debug\BestScores.mdf";
SqlConnection conn = new SqlConnection(connString);
conn.Open();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(@"SELECT * FROM Top", conn);
da.Fill(ds);//Error
Upvotes: 3
Views: 672
Reputation: 98740
Top
is a reserved keyword on Transact-SQL. When you want to use it in your sql command, you have to use it with square brackets like [TOP]
.
SqlDataAdapter da = new SqlDataAdapter(@"SELECT * FROM [Top]", conn);
That's why you are getting
Incorrect syntax near the keyword 'Top'
Upvotes: 2
Reputation: 15
Try to change the Top to another name, because TOP is a reserved word on SQL. Check this out http://www.w3schools.com/sql/sql_top.asp
Upvotes: 1