
Jet OLEDB provider: Valid wildcard SELECT returns nothing in ASP
I may have mis-stated the problem. Here's the essence of the routine:
'=================================================
Sub WriteRecords()
dim cnStr
Dim cn
Dim rs
Dim strH
Dim strVariable
strVariable = Request.QueryString("AddrLike")
Path = Server.MapPath("Customers.mdb")
cnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Path &";Jet
OLEDB:Database Password=PWD;admin;"
Set cn = server.CreateObject("ADODB.Connection")
cn.Open cnStr
set RS = server.CreateObject("ADODB.Recordset")
SQL = ""SELECT * FROM Customers WHERE Address LIKE " & Chr(34) & "*" & SQL
= SQL & strVariable & "*" & Chr(34)
rs.Open SQL,cn,3,3
Do Until rs.EOF
strH = rs("CustomerName")
rs.MoveNext
Loop
rs.Close
Set rs = nothing
cn.close
set cn = nothing
response.write strH
End Sub
'==============================
The value of the Varaible SQL equates to something like SELECT * FROM
Customers WHERE Address Like "*PO Box*". This SQL Statement, pasted as such
into the query designer of the actual database returns records (yes, I'm
using Access on the web server). When run by this asp page, however, I get
nothing. All other types of queries appear to run as expected except such
queries where I'm using Access's "*" wildcard character in the criteria.
Yes, if I move the data to SQL Server and change the double quotes to
singles and the wildcard character to % it works fine, but this is not an
option on this clients' web server. It would appear that the SQL statement
is not being parsed acurately when passed in the rs.Open argument to the
OLEDB provider by IIS.
Quote:
> Exactly, so, Define a variable and make that variable = to your SQL string
> and then use the variable to make the SQL call.
> > I have a SELECT statement:
> > "SELECT * FROM Customers WHERE Address LIKE " & Chr(34) & "*" &
> strVariable
> > & "*" & Chr(34)
> > - that returns records as expected when the resulting statement (e.g.
> > "SELECT * FROM Customers WHERE Address Like "*PO Box*") is pasted into a
> > query designer.
> > When run in an ASP page, however, I get EOF - nothing. If I
> response.write
> > the SQL statement out to the page and paste the results into a database
> > query statement, it returns the records expected.
> > Any ideas on why this is happening would be greatly appreciated.