Question read a range of rows from a table and write it to a datagridview

pooya1072

Well-known member
Joined
Jul 5, 2012
Messages
84
Programming Experience
Beginner
hi
i have a table include 100 rows . i want read 20 (or any number less than 100) rows from the end of table and write rows by rows in a datagridview . what is the best way .
best means less commands
 
There are various data access technologies available, e.g. raw ADO.NET, typed DataSets, LINQ to SQL, Entity Framework, etc. I would suggest using raw ADO.NET to begin with because everything else is built on top of that. It's good to learn what's going on underneath so you can understand what the higher-level stuff is doing and how to fix it when it doesn't work. In your case, that means using a data adapter and calling its Fill method to populate a DataTable, which you can then bind to your grid. As for your query, you'll want to sort the data in reverse order and then, assuming SQL Server, use the TOP keyword to specify how many records to retrieve. Here are some ADO.NET examples of my own:

Retrieving and Saving Data in Databases
 
Back
Top