How to properly filter 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")
        End If

        GridView1.DataSource = dt
        GridView1.DataBind()
        c.Close()

When I call da.fill, I insert all the records from my query. Then I hoped to filter them to only display those where the GroupingID value is 0. When I run the above code. All data is presented to me, the filter does not work. Please tell us how to do it right. Thank.

+5
source share
1 answer

dt.Select() returns an array of DataRows.

Why aren't you using DataView?

 DataView dv = new DataView(dt);
 dv.RowFilter = "GroupingID = 0";
 GridView1.DataSource = dv;
+11
source

All Articles