Hello,
I'm writing a C# program that interfaces with an Access database.
The database is a simple table with 2 fields: "IDPerson" (Counter field) and "NamePerson" (Text field).
In this table there are 3 records:
1) IDPerson = 1, NamePerson = "Bill"
2) IDPerson = 2, NamePerson = "Robert"
3) IDPerson = 3, NamePerson = "Tom"
After some tests I noticed that, if I create a DataView object and I use the "_" SQL jolly character to set its RowFilter property, the program doesn't function as expected:
DataView dvPersonsFiltered = new DataView();
dvPersonsFiltered.Table = dtPersons;
dvPersonsFiltered.RowFilter = "NamePerson like '_ill'";
dvPersonsFiltered.Sort = "IDPerson ASC";
int numPersonsFiltered = dvPersons.Count;
(search all the names that have "ill" string after the first generic character, and then end).
If I put a breakpoint after the numPersonsFiltered setting statement, the result is numPersonsFiltered = 0.
The strange thing is that the other SQL jolly character "%" functions correctly (but of course it has a different meaning respect to "_").
DataView dvPersonsFiltered = new DataView();
dvPersonsFiltered.Table = dtPersons;
dvPersonsFiltered.RowFilter = "NamePerson like '%ill'";
dvPersonsFiltered.Sort = "IDPerson ASC";
int numPersonsFiltered = dvPersons.Count;
(search all the names that end with "ill" string).
This time numPersons filtered = 1.
Do you know the reason of that?
Is there in C# a way to obtain a dvPersons.RowFilter setting with first character set as generic and then the "ill" string?
I could use the statement:
dvPersons.RowFilter = "NamePerson = 'Aill' OR NamePerson = 'Bill' OR ... OR NamePerson = 'Zill'";
but it would be awful, wouldn't it?
Thank you very much
I'm writing a C# program that interfaces with an Access database.
The database is a simple table with 2 fields: "IDPerson" (Counter field) and "NamePerson" (Text field).
In this table there are 3 records:
1) IDPerson = 1, NamePerson = "Bill"
2) IDPerson = 2, NamePerson = "Robert"
3) IDPerson = 3, NamePerson = "Tom"
After some tests I noticed that, if I create a DataView object and I use the "_" SQL jolly character to set its RowFilter property, the program doesn't function as expected:
DataView dvPersonsFiltered = new DataView();
dvPersonsFiltered.Table = dtPersons;
dvPersonsFiltered.RowFilter = "NamePerson like '_ill'";
dvPersonsFiltered.Sort = "IDPerson ASC";
int numPersonsFiltered = dvPersons.Count;
(search all the names that have "ill" string after the first generic character, and then end).
If I put a breakpoint after the numPersonsFiltered setting statement, the result is numPersonsFiltered = 0.
The strange thing is that the other SQL jolly character "%" functions correctly (but of course it has a different meaning respect to "_").
DataView dvPersonsFiltered = new DataView();
dvPersonsFiltered.Table = dtPersons;
dvPersonsFiltered.RowFilter = "NamePerson like '%ill'";
dvPersonsFiltered.Sort = "IDPerson ASC";
int numPersonsFiltered = dvPersons.Count;
(search all the names that end with "ill" string).
This time numPersons filtered = 1.
Do you know the reason of that?
Is there in C# a way to obtain a dvPersons.RowFilter setting with first character set as generic and then the "ill" string?
I could use the statement:
dvPersons.RowFilter = "NamePerson = 'Aill' OR NamePerson = 'Bill' OR ... OR NamePerson = 'Zill'";
but it would be awful, wouldn't it?
Thank you very much