xyz
xyz

Reputation: 13

Datable.Select sort expression

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 ?

Upvotes: 1

Views: 712

Answers (3)

Amsakanna
Amsakanna

Reputation: 12934

dtTagList.Select(string.format("tag LIKE '{0}'","UNKNOWN%"))

Upvotes: 0

Matt Hamilton
Matt Hamilton

Reputation: 204129

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%'");

Upvotes: 0

Anthony Pegram
Anthony Pegram

Reputation: 126844

DataRow[] rows = dt.Select("tag like 'UNKNOWN%'");

Upvotes: 3

Related Questions