JPJedi JPJedi - 2 years ago 123 Question

Return top 5 records of a table in a dataset

I want to return the top 5 records of a table in a dataset for datagrid view. The following does not work.

DataGridView.DataSource = DS.Tables("TABLENAME").Select("SELECT TOP 5")

Any suggestions?

Using Visual Studio 2008 - VB.Net

Answer Source

If the dataset is already populated, you can use LINQ to take the first 5 rows from a table. (The more efficient method would be to handle this at the database, however.)

Dim rows = DS.Tables("Foo").Rows.Cast(Of DataRow)().Take(5)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download