Substring test in DataTable.Select ()

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

Is there any syntax to use in the Select () method that allows a substring of a column test, or do I need to do this in a complicated way - scanning each row.

+3
source share
3 answers

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

table.Select("ItemName LIKE '*product*'")
+5
source

Perhaps you can use linq, as in 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");
+4
source

You can use a substring.

DataRow[] selectRowsWithSubstring;
selectRowsWithSubstring = datatable.Select("substring(column, start, length) = value");
-1
source

Source: https://habr.com/ru/post/1725200/


All Articles