views:

319

answers:

2

I have a DataTable with results already pulled down from a back end. I want to do a DataTable.Select(), but the criteria is based on a SUBSTRING of one of the columns.

Is there syntax to use in the Select() method that allows for substring of a column test, or do I have to do it the hard way -- scan each row.

+1  A: 

You can use the LIKE operator in the expression given to Select():

table.Select("ItemName LIKE '*product*'")
Amnon
+2  A: 

Maybe you could use linq, like the following example:

var x = from c in table.AsEnumerable()
        select c.Field<string>("MyColumn").Substring(index, length);

or

var x = from c in table.AsEnumerable()
        select c.Field<string>("MyColumn").Contains("MySearchString");
Webleeuw