Breezeight
Breezeight

Reputation: 1991

c# DataTable.Select: problem with '-' character

I have a problem in a C# project. I am using the Select method with a DataTable object. If I put a '-' in the search string I select nothing. So here is a code sample of what I have:

DataTable table;
DataRow[] rows = table.Select("[Radio Name] LIKE '*Lounge-MP3-96*'");

But there is a column with: Radio Name = 1.FM - The Chillout Lounge-MP3-96

Have I to escape characters? How?

I've just tried

DataTable table;
DataRow[] rows = table.Select("[Radio Name] LIKE '*Lounge*'");

It works! So it seems really related to the "-"....

Upvotes: 0

Views: 2791

Answers (1)

Neil Barnwell
Neil Barnwell

Reputation: 42105

I don't think it's the "-". I thought wildcards needed to be percent symbols for the datatable select (it mimics SQL): "%"?

Try this:

DataTable table = GetTableFromSomewhere();
DataRow[] rows = table.Select("[Radio Name] LIKE '%Lounge-MP3-96%'");

Also, your example doesn't populate the table with anything in the first place so it wouldn't work - I'm assuming you do populate your table somehow.

Upvotes: 6

Related Questions