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")
End If
GridView1.DataSource = dt
GridView1.DataBind()
c.Close()
When I call da.fill I am inserting all records from my query. I was then hoping to filter them to display only those where the GroupingID is equal to 0. When I run the above code. I am presented with all the data, the filter did not work. Please can you tell me how to get this working correctly. Thanks.
dt.Select()
returns an array of DataRows.
Why don't you use a DataView?
DataView dv = new DataView(dt);
dv.RowFilter = "GroupingID = 0";
GridView1.DataSource = dv;
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 As New DataTable
Dim dv As New DataView(dt)
dv.RowFilter = "GroupingID = 0"
DataGridView1.DataSource = dv
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With