Error in RowFilter Like Operation

K

King Kong

Hi,

I am facing misterious problem while setting up RowFilter property of
DataView.

It works find when i do

dv.RowFilter = "StudentName like 'Dave'"
or
dv.RowFilter = "StudentName like '%Dave'"


but it breaks up when i do
dv.RowFilter = "StudentName like 'Da%v%e'"
or use wild cards, or repeat the above case.

with this error:
Error in Like operator: the string pattern 'Da%v%e' is invalid rowfilter.

Interesting part is this query works good on MS SQL server, it must.

I dont know if ths is a limitation by manufacturer of .NET?

i'd be thankful of any help.

Regards
KK
 
J

Jon Skeet [C# MVP]

King Kong said:
I am facing misterious problem while setting up RowFilter property of
DataView.

It's not that mysterious really :)
It works find when i do

dv.RowFilter = "StudentName like 'Dave'"
or
dv.RowFilter = "StudentName like '%Dave'"

but it breaks up when i do
dv.RowFilter = "StudentName like 'Da%v%e'"
or use wild cards, or repeat the above case.

Yup. From the documentation for DataColumn.Expression (linked from
DataView.RowFilter):

<quote>
Both the * and % can be used interchangeably for wildcards in a LIKE
comparison. If the string in a LIKE clause contains a * or %, those
characters should be escaped in brackets ([]). If a bracket is in the
clause, the bracket characters should be escaped in brackets (for
example [[] or []]). A wildcard is allowed at the beginning and end of
a pattern, or at the end of a pattern, or at the beginning of a
pattern. For example:

"ItemName LIKE '*product*'"

"ItemName LIKE '*product'"

"ItemName LIKE 'product*'"

Wildcards are not allowed in the middle of a string. For example,
'te*xt' is not allowed.
</quote>

Basically, it's much more restrictive than SQL Server, which is fair
enough really, IMO. I just wish you could specify a delegate to use for
filtering, rather than just a text string. That would make it *much*
more powerful.
 
M

Miha Markic [MVP C#]

Hi Jon,
Basically, it's much more restrictive than SQL Server, which is fair
enough really, IMO. I just wish you could specify a delegate to use for
filtering, rather than just a text string. That would make it *much*
more powerful.

And the same for sorting, yes :).
Another approach is to add a filtering or a sorting column and put there
values manually...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top