Link to home
Start Free TrialLog in
Avatar of englishman
englishman

asked on

apostrophe in asp search

When I use an apostrophe as part of a serch term - eg:
"men's thoughts"
I get a syntax error returned.
What is the workaround without replacing these in the database and then replacing them back in the search results?
Cheers
Avatar of siabod
siabod

If you have a string like this :

<%MyString="men's thoughts"%>

and you insert it into the database, do it like this:

<%sql="insert into tablename (fieldname) values ('"&server.htmlencode(MyString)&"')"%>

The function server.htmlencode handles the apostrophe, when you read it from the database you don't need to do anything

Hope it helps you

Avatar of englishman

ASKER

I think I get what you mean but the database is not updated online; it is converted from some other format, then uploaded.
Could you provide more information then ?
cos a normal select wouldn't be doing difficult on it...
Just a normal select on a normal access table.

Keywords = Request.form("Keywords")
q = "SELECT * FROM dbase WHERE Keywords LIKE '%" & Keywords & "%"
(Actually a little more complex but essentially the same)
- or -

<%
MyString = replace(MyString, "'", "''")
%>

repace the single' with two ''.  This will also work...
Massey,
You're a star.
Nick
-grab points
ASKER CERTIFIED SOLUTION
Avatar of MasseyM
MasseyM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial