Datable.Select sort expression

712 Views Asked by At

I have datatable with column name tag and 100 rows of data.I need to filter this table with tag starting with "UNKNOWN".

What should my sortexpression for datatable.select be ?

I'm trying the following.

Datarow[] abc = null;
abc = dtTagList.Select(string.format("tag='{0}'","UNKNOWN"))

How can I achieve tag startswith 'UNKNOWN' in the above code ?

3

There are 3 best solutions below

0
Anthony Pegram On BEST ANSWER
DataRow[] rows = dt.Select("tag like 'UNKNOWN%'");
0
Matt Hamilton On

Well, obviously you don't need to pass in a sort expression - you want a filter expression.

According to the MSDN article on DataTable.Select, the expression you pass in obeys the same rules as the DataColumn.Expression property, which supports the LIKE operator.

So give this a whirl:

abc = dtTagList.Select("tag LIKE 'UNKNOWN%'");
0
Amsakanna On
dtTagList.Select(string.format("tag LIKE '{0}'","UNKNOWN%"))