1

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 ?

Igor
  • 33,276
  • 14
  • 79
  • 112
xyz
  • 13
  • 2

3 Answers3

3
DataRow[] rows = dt.Select("tag like 'UNKNOWN%'");
Anthony Pegram
  • 123,721
  • 27
  • 225
  • 246
0

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
  • 200,371
  • 61
  • 386
  • 320
0
dtTagList.Select(string.format("tag LIKE '{0}'","UNKNOWN%"))
Amsakanna
  • 12,254
  • 8
  • 46
  • 58