Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataView.RowFilter() problem with Single Quotes

Status
Not open for further replies.

miket26

Programmer
Apr 13, 2004
63
CA
Hi,

Has anyone used Dataview.rowfilter() and had to look for strings that contained a single quote. This will cause an error, since the single quote is a 'reserved' character in the filter expression. Anyone know how to work around this and also be able to still query for a string containing a single quote?

Thanks
 
I believe you can do something like:

"first part of string to search" & Chr(39) & "next part of string to search"

replacing the single quote with the Chr(39)

Dale
 
I'm not sure about the dataview.rowfilter, but quite often escape characters (\) are used. So you could send it something like this:

Code:
dataview.rowfilter = SearchString.replace("'","\'")

I'm not sure if RowFilter supports this or not though.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Hi,

Thanks for the suggestions, but neither were able to work. Here is an example of what I'm doing:

dataview1.rowfilter = "City = 'Mike's City'"

The problem is that single quote in the middle will cause the expression to fail.

 
Hi Rick,

In the dataset, the value is actually "Mike's City", so I don't think the filter wouldn't find the search string. I also wouldn't want to alter the database or restrict the input into the database to convert single quotes into double quotes, so that I can easily query it. I would greatly appreciate more suggestions should anyone have any.

Thanks
 
Rick,

You were right. I thought it wasn't working because the results were not showing in my datagrid, but I had a problem with the datagrid and mistakingly thought it was the filter. I fixed the problem and it worked great. Thanks for the tip!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top