03-26-07 06:35 AM
Dave wrote:
> Thanks Bob
>
> I think there is something fundamental I'm missing here.
>
> I am not using dynamic SQL,
I know you're not.
> my query resides on Access so in the
> Access application the WHERE clause below returns over 1000 records:
Yes I know. Access uses DAO to execute your stored queries, so the Jet
wildcards can be used. When executing queries, even saved queries, via ADO,
the ODBC wildcards must be used. It's very nonintuitive, I know.
>
> WHERE (((Example.Example) Like "*" & [pSearch] & "*"));
>
> While this returns 0 records:
>
> WHERE (((Example.Example) Like "%" & [pSearch] & "%"));
>
> Both of these WHERE clasues return 0 records to my ASP page.
>
The latter should work. I've just tested it with this sample data:
abcd
efgh
halp
pqrs
I created a saved query called "wildcardsearch" with this sql:
SELECT Example
FROM Example
WHERE Example Like "%" & [psearch] & "%";
Using this code to execute the saved query:
<%
dim cn, rs, s
s="a"
set cn=createobject("adodb.connection")
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & server.MapPath("db7.mdb")
set rs=createobject("adodb.recordset")
cn.wildcardsearch s,rs
if not rs.EOF then
Response.Write rs.GetString(,,,"<BR>")
else
Response.Write "No records retrieved"
end if
rs.Close
cn.Close
%>
I get this result:
abcd
halp
--
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"
[ Post a follow-up to this message ]
|