开发者

Substring test within DataTable.Select()

开发者 https://www.devze.com 2022-12-13 12:27 出处:网络
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.

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");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号