views:

82

answers:

3

Hi,

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 ?

+2  A: 
DataRow[] rows = dt.Select("tag like 'UNKNOWN%'");
Anthony Pegram
A: 

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%'");
Matt Hamilton
A: 
dtTagList.Select(string.format("tag LIKE '{0}'","UNKNOWN%"))
Veer