tags:

views:

520

answers:

2

Hi! 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 "-"....

+5  A: 

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.

Neil Barnwell
In fact it works with both of them... i've just test it and it works
Jhonny D. Cano -Leftware-
Oh right, way for MS to be consistent, then.
Neil Barnwell
A: 

Can you specify patterns in DataTable.Select such as .Select("Number 1 But not with0 next to it?") ??

ShauneyB