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
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With