Archive for the ‘.NET General Topic’ Category

Overcoming RowFilter and Select Limitation

In ADO.NET, you can use the DataView.RowFilter property and the DataTable.Select method to filter a subset of records. However, the expressions that you can use have limitations. This article demonstrates three techniques to work around the limitations of the filter expressions.

[vbnet]
‘DataTable1 is an existing DataTable object.
DataTable1.Columns.Add(“Flag”, GetType(Boolean))
DataTable1.Columns(“Flag”).ColumnMapping = MappingType.Hidden
Dim dr As DataRow
For Each dr In DataTable1.Rows
‘ If the criteria are satisfied Then
dr(“Flag”) = True
‘ End If
Next
Dim dv As New DataView(DataTable1, “Flag = True”, “”, DataViewRowState.CurrentRows)
DataGrid1.DataSource = dv
[/vbnet]