How to correctly filter a datatable (datatable.select)

前端 未结 3 455
小蘑菇
小蘑菇 2021-01-12 10:02
Dim dt As New DataTable
Dim da As New SqlDataAdapter(s, c)

        c.Open()
        If Not IsNothing(da) Then
            da.Fill(dt)
            dt.Select(\"Groupi         


        
相关标签:
3条回答
  • 2021-01-12 10:08

    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 As New DataTable:Dim dv As New DataView(dt):dv.RowStateFilter = "GroupingID = 0":DataGridView1.DataSource = dv
    
    0 讨论(0)
  • 2021-01-12 10:10

    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
    
    0 讨论(0)
  • 2021-01-12 10:31

    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;
    
    0 讨论(0)
提交回复
热议问题