DataTable filtering (Like)

  • Thread starter Thread starter TA
  • Start date Start date
T

TA

Hi,

Does anyone know if it is possible to filter rows in a DataTable by pattern
(e.g. Like in SQL)

For instance I want to select all rows containing the 'rob' in the name
column.

Any ideas?
- TA
 
Yes, you can use a dataview and set it's rowfilter.

DataView dv = myDataTable.DefaultView;
dv.RowFilter = "FirstField LIKE 'whatever%'"
 
TA,
In addition to the DataView as William stated, you can also use the
DataTable.Select method to return an array of DataRows.

The biggest difference being is the DataView is bindable, while the Select
is not.

If I need the rows in a For Each I normally use DataTable.Select, otherwise
I normally use the DataView.

Hope this helps
Jay
 
Thanks guys,
Appreciate teh Help

Jay B. Harlow said:
TA,
In addition to the DataView as William stated, you can also use the
DataTable.Select method to return an array of DataRows.

The biggest difference being is the DataView is bindable, while the Select
is not.

If I need the rows in a For Each I normally use DataTable.Select, otherwise
I normally use the DataView.

Hope this helps
Jay
 
Back
Top