Substring test within DataTable.Select()
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.
You can use the LIKE operator in the expression given to Select():
table.Select("ItemName LIKE '*product*'")
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");
You can use substring.
DataRow[] selectRowsWithSubstring;
selectRowsWithSubstring = datatable.Select("substring(column, start, length) = value");
精彩评论