Skip to content Skip to sidebar Skip to footer

How To Correctly Filter A Datatable (datatable.select)

Dim dt As New DataTable Dim da As New SqlDataAdapter(s, c) c.Open() If Not IsNothing(da) Then da.Fill(dt) dt.Select('GroupingID = 0')

Solution 1:

dt.Select() returns an array of DataRows.

Why don't you use a DataView?

DataView dv = newDataView(dt);
 dv.RowFilter = "GroupingID = 0";
 GridView1.DataSource = dv;

Solution 2:

Junt in case... Think you've got a small typo in your VB.NET code. It should be dv.RowFilter instead of dv.RowStateFilter, so:

Dim dt AsNew DataTable
Dim dv AsNew DataView(dt)
dv.RowFilter = "GroupingID = 0"
DataGridView1.DataSource = dv

Solution 3:

The accepted answer is correct, though it should have been given in vb.net to better benefit the one that asked the question. Here it is in VB.Net:

Dim dt AsNew DataTable:Dim dv AsNew DataView(dt):dv.RowStateFilter = "GroupingID = 0":DataGridView1.DataSource = dv

Post a Comment for "How To Correctly Filter A Datatable (datatable.select)"