Wednesday, August 18, 2010

Filter DataTable with Select method of DataTable

Private Function GetRowsByBlockIdFilter(ByVal dt As DataTable, ByVal blockId As String) As DataTable

Dim table As DataTable = dt.Copy()
dt.Rows.Clear()

Dim expression As String
expression = "blockId='" + blockId.Trim() + "' "
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)
dt.ImportRow(foundRows(i))

Next i

Return dt
End Function

No comments:

Post a Comment

 
Locations of visitors to this page