Rabu, 04 Juli 2012

How to FIlter DataTable in DataSet in VB.Net

Below is examples of VB.Net source code to filter data in a datatable within a dataset (source : MSDN)

Di bawah ini adalah contoh untuk melakukan filter data yang terdapat pada datatable di dataset. Sumber : MSDN.

Private Sub GetRowsByFilter()
    
    Dim table As DataTable = DataSet1.Tables("Orders")

    ' Presuming the DataTable has a column named Date.
    Dim expression As String
    expression = "Date > '1/1/00'"
    Dim foundRows() As DataRow

    ' Use the Select method to find all rows matching the filter.
    foundRows = table.Select(expression)

    Dim i As Integer
    ' Print column 0 of each returned row.
    For i = 0 to foundRows.GetUpperBound(0)
       Console.WriteLine(foundRows(i)(0))
    Next i
End Sub
Private Sub GetRowsByFilter()
    Dim table As DataTable = DataSet1.Tables(0)

    ' Presuming the DataTable has a column named Date.
    Dim expression As String = "Date > 1/1/00"

    ' Sort descending by column named CompanyName.
    Dim sortOrder As String = "CompanyName DESC" 
    Dim foundRows() As DataRow

    ' Use the Select method to find all rows matching the filter.
    foundRows = table.Select(expression, sortOrder)

    Dim i As Integer
    ' Print column 0 of each returned row.
    For i = 0 to foundRows.GetUpperBound(0)
       Console.WriteLine(foundRows(i)(0))
    Next i
End Sub

Tidak ada komentar: