Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Populating Dataset from DataAdapter error

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
like image 548
Adrian Tanase Avatar asked Jul 21 '26 16:07

Adrian Tanase


1 Answers

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'

like image 91
Soner Gönül Avatar answered Jul 24 '26 05:07

Soner Gönül



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!