ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 8th, 2003, 08:36 AM
m175400 m175400 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 19 m175400 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy Searching for apostrophes in Access returns no matches

Having been advised that using parameterized SQL statements in Access was more efficient and reliable that an ordinary SQL statement, I decided to give it a try. The problem was that when searching for strings containing an ', it would return only one result, or less than was actually there.

Searching for anything else returns the correct results.

My original SQL statements was as follows:

strSQL = "select id as strID, tableID as strTableID, tagline as strTagline, content AS strContact FROM news where tagline LIKE '%" & searchString & "%' OR content LIKE '% " & searchString & "%' UNION ALL select id as strID, tableID as strTableID, tagline AS strTagline, content AS strContent from databank where tagline LIKE '%" & searchString & "%' OR content LIKE '%" & searchString & "%' ORDER BY strID"

Anyway, I even tried changing instances of ' in the database for &apos; but again it just returned the one or incorrect no. of results.

Now I have written a query called 'qrySearch' in access as follows:

==============================================
PARAMETERS searchText Text ( 255 );
SELECT id as strID, tableID as strTableID, tagline as strTagline, content AS strContact FROM news where

(((tagline)LIKE[searchText]))


OR

(((content)LIKE[searchText]))


UNION ALL select id as strID, tableID as strTableID, tagline AS strTagline, content AS strContent from databank WHERE

(((tagline)LIKE[searchText]))


OR

(((content)LIKE[searchText]))
ORDER BY strID;
==============================================


My ASP is as follows:


==============================================
Dim objRS, objComm, objParam, strDirector
Set objComm = Server.CreateObject("ADODB.Command")

objComm.ActiveConnection = DB 'strConnect ' fill in the command properties
objComm.CommandText = "qrySearch"
objComm.CommandType = adCmdStoredProc

' now the parameters (actually, there's only one parameter here)
Set objParam = _
objComm.CreateParameter("searchText", adVarChar, adParamInput, 50)
objComm.Parameters.Append objParam

strSearchText = searchString ' you can change this if you like
objComm.Parameters("searchText") = strSearchText

Set objRS = objComm.Execute ' execute the command and generate the recordset

Set objComm = Nothing ' don't need the Command and Parameter objects
Set objParam = Nothing ' ... so we can clean them up
==============================================

It doesn't generate any errors, but now it returns no matches regardless of what I search for, have it an ' in it or not.

PLEASE PLEASE PLEASE can somebody help me?! I'm getting very frustrated and confused now

Hope to hear from you soon, and thanks in advance!

Reply With Quote
  #2  
Old October 8th, 2003, 09:49 AM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 12th Plane (10500 - 10999 posts)
 
Join Date: Jun 2003
Posts: 10,991 Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 19 h 36 m 58 sec
Reputation Power: 814
You need to replace single ' with two of them in your search string, something like

objComm.Parameters("searchText") = Replace(strSearchText, " ' ", " ' ' ") 'spaces for readability

Reply With Quote
  #3  
Old October 8th, 2003, 10:04 AM
m175400 m175400 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 19 m175400 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally posted by Doug G
You need to replace single ' with two of them in your search string, something like

objComm.Parameters("searchText") = Replace(strSearchText, " ' ", " ' ' ") 'spaces for readability


Thanks, but I tried that originally, before I even gave parameterized statements a go. Again, returns the wrong number of results, or having just tried it now, no results at all, even when searching for a string containing no apostrohes at all.

Reply With Quote
  #4  
Old October 8th, 2003, 10:11 AM
m175400 m175400 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 19 m175400 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Having played with my query 'qrySearch' in access, it seems that doesn't return any results in itself, so the problem must lie there. I thought I had tested this but maybe I am wrong.

Can anyone see what the problem witht he query itself (below) is please?


PARAMETERS searchText Text ( 255 );
SELECT id as strID, tableID AS strTableID, tagline AS strTagline, content AS strContact FROM news WHERE

(((news.tagline)LIKE[searchText]))


OR

(((news.content)LIKE[searchText]))


UNION ALL select id AS strID, tableID AS strTableID, tagline AS strTagline, content AS strContent FROM databank WHERE

(((databank.tagline)LIKE[searchText]))


OR

(((databank.content)LIKE[searchText]))
ORDER BY strID;

Last edited by m175400 : October 8th, 2003 at 10:14 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Searching for apostrophes in Access returns no matches


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT