JPJedi JPJedi - 3 days ago 6
Vb.net 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

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)
Comments