Problem with query LIKE and Access

This is a discussion on Problem with query LIKE and Access within the Inetserver forums in Microsoft Tools category; Hi all I have a problem with an ASP page and an Access query The following query works fine into Access 2007 SELECT tbl_gallery.id, tbl_gallery.nome, tbl_gallery.luogo, tbl_gallery.provincia, tbl_gallery.data, tbl_gallery.descrizione, tbl_gallery.esposizione, tbl_gallery.diorama, tbl_gallery.privato, tbl_gallery.cap, tbl_gallery.telefono, tbl_gallery.online FROM tbl_gallery WHERE (((tbl_gallery.nome) Like [?] & "*") AND ((tbl_gallery.diorama)=No) AND ((tbl_gallery.online)=Yes)) ORDER BY tbl_gallery.nome; it extract all the name starting with the letter I specify anyway when I call the query into an ASP page I get no records shown here a snippet... Set rs_pres_amici = Server.CreateObject("ADODB.Recordset") rs_pres_amici.cursorlocation = 3 con_pres_amici.q_gallery chiave, rs_pres_amici totalRecs = rs_pres_amici.RecordCount quanti = 20 pag = Request.QueryString("pag") If IsNumeric(pag) ...

Go Back   Application Development Forum > Microsoft Tools > Inetserver

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-08-2008, 05:22 AM
Paolo Galli
Guest
 
Default Problem with query LIKE and Access

Hi all I have a problem with an ASP page and an Access query

The following query works fine into Access 2007

SELECT tbl_gallery.id, tbl_gallery.nome, tbl_gallery.luogo,
tbl_gallery.provincia, tbl_gallery.data, tbl_gallery.descrizione,
tbl_gallery.esposizione, tbl_gallery.diorama, tbl_gallery.privato,
tbl_gallery.cap, tbl_gallery.telefono, tbl_gallery.online
FROM tbl_gallery
WHERE (((tbl_gallery.nome) Like [?] & "*") AND
((tbl_gallery.diorama)=No) AND ((tbl_gallery.online)=Yes))
ORDER BY tbl_gallery.nome;

it extract all the name starting with the letter I specify

anyway when I call the query into an ASP page I get no records shown
here a snippet...


Set rs_pres_amici = Server.CreateObject("ADODB.Recordset")

rs_pres_amici.cursorlocation = 3
con_pres_amici.q_gallery chiave, rs_pres_amici

totalRecs = rs_pres_amici.RecordCount

quanti = 20

pag = Request.QueryString("pag")
If IsNumeric(pag) = False Or pag < 1 Then pag = 1

contatore = 0

If rs_pres_amici.EOF then

I always get NO RECORDS FOUND

where is my error ?

thanks
Paolo
Reply With Quote
  #2  
Old 08-08-2008, 07:55 AM
Bob Barrows [MVP]
Guest
 
Default Re: Problem with query LIKE and Access

Paolo Galli wrote:
> Hi all I have a problem with an ASP page and an Access query
>
> The following query works fine into Access 2007
>
> SELECT tbl_gallery.id, tbl_gallery.nome, tbl_gallery.luogo,
> tbl_gallery.provincia, tbl_gallery.data, tbl_gallery.descrizione,
> tbl_gallery.esposizione, tbl_gallery.diorama, tbl_gallery.privato,
> tbl_gallery.cap, tbl_gallery.telefono, tbl_gallery.online
> FROM tbl_gallery
> WHERE (((tbl_gallery.nome) Like [?] & "*") AND
> ((tbl_gallery.diorama)=No) AND ((tbl_gallery.online)=Yes))
> ORDER BY tbl_gallery.nome;
>


The wildcards used _in Access_ are * and ?

These wildcards must be replaced by the ODBC wildcards % and _ when running
queries via ADO. Even when running saved queries. It's weird, I know, but
replace * with % and give it a try.


--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


Reply With Quote
  #3  
Old 08-08-2008, 09:11 AM
Paolo Galli
Guest
 
Default Re: Problem with query LIKE and Access

Thanks Bob, now I can retrieve the data but...

if I hard encoded the string value into the query

con_pres_amici.q_gallery "c", rs_pres_amici

I get results... if I do

con_pres_amici.q_gallery chiave, rs_pres_amici

I don't

query now is

SELECT tbl_gallery.id, tbl_gallery.nome, tbl_gallery.luogo,
tbl_gallery.provincia, tbl_gallery.data, tbl_gallery.descrizione,
tbl_gallery.esposizione, tbl_gallery.diorama, tbl_gallery.privato,
tbl_gallery.cap, tbl_gallery.telefono, tbl_gallery.online
FROM tbl_gallery
WHERE (((tbl_gallery.nome) Like [?] & "%") AND
((tbl_gallery.diorama)=No) AND ((tbl_gallery.online)=Yes))
ORDER BY tbl_gallery.nome;

I get the query parameter this way

If not Request.QueryString("chiave").Count > 0 Then
If IsNumeric( chiave ) OR chiave ="" Then chiave = "a"
End If

In fact if I omit the chiave parametr the query works but when I call
the URL (i.e http://localhost/test.asp?chiave=b ) I get an error

Parameter object is improperly defined. Inconsistent or incomplete
information was provided. the line pointed is the above one
(con_pres_amici.q_gallery chiave, rs_pres_amici)

what's wrong?

thanks
Paolo

Bob Barrows [MVP] wrote:
> Paolo Galli wrote:
>> Hi all I have a problem with an ASP page and an Access query
>>
>> The following query works fine into Access 2007
>>
>> SELECT tbl_gallery.id, tbl_gallery.nome, tbl_gallery.luogo,
>> tbl_gallery.provincia, tbl_gallery.data, tbl_gallery.descrizione,
>> tbl_gallery.esposizione, tbl_gallery.diorama, tbl_gallery.privato,
>> tbl_gallery.cap, tbl_gallery.telefono, tbl_gallery.online
>> FROM tbl_gallery
>> WHERE (((tbl_gallery.nome) Like [?] & "*") AND
>> ((tbl_gallery.diorama)=No) AND ((tbl_gallery.online)=Yes))
>> ORDER BY tbl_gallery.nome;
>>

>
> The wildcards used _in Access_ are * and ?
>
> These wildcards must be replaced by the ODBC wildcards % and _ when running
> queries via ADO. Even when running saved queries. It's weird, I know, but
> replace * with % and give it a try.
>
>

Reply With Quote
  #4  
Old 08-08-2008, 10:02 AM
Bob Barrows [MVP]
Guest
 
Default Re: Problem with query LIKE and Access

Paolo Galli wrote:
> Thanks Bob, now I can retrieve the data but...
>
> if I hard encoded the string value into the query
>
> con_pres_amici.q_gallery "c", rs_pres_amici
>
> I get results... if I do
>
> con_pres_amici.q_gallery chiave, rs_pres_amici
>
> I don't
>
> query now is
>
> SELECT tbl_gallery.id, tbl_gallery.nome, tbl_gallery.luogo,
> tbl_gallery.provincia, tbl_gallery.data, tbl_gallery.descrizione,
> tbl_gallery.esposizione, tbl_gallery.diorama, tbl_gallery.privato,
> tbl_gallery.cap, tbl_gallery.telefono, tbl_gallery.online
> FROM tbl_gallery
> WHERE (((tbl_gallery.nome) Like [?] & "%") AND
> ((tbl_gallery.diorama)=No) AND ((tbl_gallery.online)=Yes))
> ORDER BY tbl_gallery.nome;
>
> I get the query parameter this way
>
> If not Request.QueryString("chiave").Count > 0 Then
> If IsNumeric( chiave ) OR chiave ="" Then chiave = "a"
> End If
>
> In fact if I omit the chiave parametr the query works but when I call
> the URL (i.e http://localhost/test.asp?chiave=b ) I get an error
>
> Parameter object is improperly defined. Inconsistent or incomplete
> information was provided. the line pointed is the above one
> (con_pres_amici.q_gallery chiave, rs_pres_amici)
>
> what's wrong?
>

You don't seem to have passed the parameter. Does chiave contain a value? I
don't see shere you assign a value to it if the querystring variable
contains a value and it is not numeric. I would have done this:

chiave = Request.QueryString("chiave")

if len(chiave) > 0 then
if isnumeric(chiave) then
chiave = "a"
end if
else
chiave = "a"
end if

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


Reply With Quote
  #5  
Old 08-08-2008, 10:16 AM
Paolo Galli
Guest
 
Default Re: Problem with query LIKE and Access

OK but when I click on
http://localhost/test.asp?chiave=b

I get the error message pointing the line

con_pres_amici.q_gallery chiave, rs_pres_amici

Paolo


Bob Barrows [MVP] wrote:
> Paolo Galli wrote:
>> Thanks Bob, now I can retrieve the data but...
>>
>> if I hard encoded the string value into the query
>>
>> con_pres_amici.q_gallery "c", rs_pres_amici
>>
>> I get results... if I do
>>
>> con_pres_amici.q_gallery chiave, rs_pres_amici
>>
>> I don't
>>
>> query now is
>>
>> SELECT tbl_gallery.id, tbl_gallery.nome, tbl_gallery.luogo,
>> tbl_gallery.provincia, tbl_gallery.data, tbl_gallery.descrizione,
>> tbl_gallery.esposizione, tbl_gallery.diorama, tbl_gallery.privato,
>> tbl_gallery.cap, tbl_gallery.telefono, tbl_gallery.online
>> FROM tbl_gallery
>> WHERE (((tbl_gallery.nome) Like [?] & "%") AND
>> ((tbl_gallery.diorama)=No) AND ((tbl_gallery.online)=Yes))
>> ORDER BY tbl_gallery.nome;
>>
>> I get the query parameter this way
>>
>> If not Request.QueryString("chiave").Count > 0 Then
>> If IsNumeric( chiave ) OR chiave ="" Then chiave = "a"
>> End If
>>
>> In fact if I omit the chiave parametr the query works but when I call
>> the URL (i.e http://localhost/test.asp?chiave=b ) I get an error
>>
>> Parameter object is improperly defined. Inconsistent or incomplete
>> information was provided. the line pointed is the above one
>> (con_pres_amici.q_gallery chiave, rs_pres_amici)
>>
>> what's wrong?
>>

> You don't seem to have passed the parameter. Does chiave contain a value? I
> don't see shere you assign a value to it if the querystring variable
> contains a value and it is not numeric. I would have done this:
>
> chiave = Request.QueryString("chiave")
>
> if len(chiave) > 0 then
> if isnumeric(chiave) then
> chiave = "a"
> end if
> else
> chiave = "a"
> end if
>

Reply With Quote
  #6  
Old 08-08-2008, 10:39 AM
Paolo Galli
Guest
 
Default Re: Problem with query LIKE and Access

wow... I didn't understood clearly
sorry.. it work fine

thanks a lot

Bob Barrows [MVP] wrote:
> Paolo Galli wrote:
>> Thanks Bob, now I can retrieve the data but...
>>
>> if I hard encoded the string value into the query
>>
>> con_pres_amici.q_gallery "c", rs_pres_amici
>>
>> I get results... if I do
>>
>> con_pres_amici.q_gallery chiave, rs_pres_amici
>>
>> I don't
>>
>> query now is
>>
>> SELECT tbl_gallery.id, tbl_gallery.nome, tbl_gallery.luogo,
>> tbl_gallery.provincia, tbl_gallery.data, tbl_gallery.descrizione,
>> tbl_gallery.esposizione, tbl_gallery.diorama, tbl_gallery.privato,
>> tbl_gallery.cap, tbl_gallery.telefono, tbl_gallery.online
>> FROM tbl_gallery
>> WHERE (((tbl_gallery.nome) Like [?] & "%") AND
>> ((tbl_gallery.diorama)=No) AND ((tbl_gallery.online)=Yes))
>> ORDER BY tbl_gallery.nome;
>>
>> I get the query parameter this way
>>
>> If not Request.QueryString("chiave").Count > 0 Then
>> If IsNumeric( chiave ) OR chiave ="" Then chiave = "a"
>> End If
>>
>> In fact if I omit the chiave parametr the query works but when I call
>> the URL (i.e http://localhost/test.asp?chiave=b ) I get an error
>>
>> Parameter object is improperly defined. Inconsistent or incomplete
>> information was provided. the line pointed is the above one
>> (con_pres_amici.q_gallery chiave, rs_pres_amici)
>>
>> what's wrong?
>>

> You don't seem to have passed the parameter. Does chiave contain a value? I
> don't see shere you assign a value to it if the querystring variable
> contains a value and it is not numeric. I would have done this:
>
> chiave = Request.QueryString("chiave")
>
> if len(chiave) > 0 then
> if isnumeric(chiave) then
> chiave = "a"
> end if
> else
> chiave = "a"
> end if
>

Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 05:24 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.