472,345 Members | 1,533 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,345 software developers and data experts.

Using wildcard w/Access database

[I posted this in the Access forum but the more I think of it, it's probably
more of an ADO issue since I can get it to work in Access but not ASP 30.]

I need to filter an Access 2000 result set in ASP 30 using the ADO
recordset.filter.

I build the filter in pieces. The first clause of the filter is this...

WHERE word LIKE 'S%'

... to which other clauses are appended with AND.

This all works fine as long as I provide a condition for the first clause
(e.g., word LIKE 'S%').

However, if no condition is specified for the "Word LIKE" clause, I need to
pass a wild card and this is where I have a problem.

I tried constructing the following clauses and encountered the problems
indicated:

sFilter = "word LIKE '%' "
'Arguments are of the wrong type, are out of acceptable range, or are in
conflict with one another.

sFilter = "word LIKE '*' "
'Arguments are of the wrong type, are out of acceptable range, or are in
conflict with one another.

sFilter = "word LIKE ""%"" "
'Empty result set

sFilter = "word LIKE ""*"" "
'Empty result set rs.filter=sFilter

Yet when I try to query directly in Access...

SELECT vWords.Word
FROM vWords
WHERE word LIKE '*';

...it works fine and returns all records.

But this...

SELECT vWords.Word
FROM vWords
WHERE word LIKE '%';

,,,does not return any records
So I am confused about wild cards in Access with ADO.

Without going through complicated logic in the ASP page to test each clause
to build one of several filter sets, how can I pass a wild card to return
all records for a certain condition?

IOW, how do I specify a filter that does this: WHERE word LIKE '*'; in my
ASP 30 page.


Feb 25 '07 #1
5 6382
% is the correct wildcard for ADO.

Why don't you just leave out the LIKE clause entirely when you're not
filtering results?

SELECT vWords.Word
FROM vWords
WHERE word LIKE '*';

Is the same as

SELECT vWords.Word
FROM vWords
Bob Lehmann

"Dave" <da*******@newsgroup.nospamwrote in message
news:er*************@TK2MSFTNGP02.phx.gbl...
[I posted this in the Access forum but the more I think of it, it's
probably
more of an ADO issue since I can get it to work in Access but not ASP 30.]

I need to filter an Access 2000 result set in ASP 30 using the ADO
recordset.filter.

I build the filter in pieces. The first clause of the filter is this...

WHERE word LIKE 'S%'

.. to which other clauses are appended with AND.

This all works fine as long as I provide a condition for the first clause
(e.g., word LIKE 'S%').

However, if no condition is specified for the "Word LIKE" clause, I need
to
pass a wild card and this is where I have a problem.

I tried constructing the following clauses and encountered the problems
indicated:

sFilter = "word LIKE '%' "
'Arguments are of the wrong type, are out of acceptable range, or are
in
conflict with one another.

sFilter = "word LIKE '*' "
'Arguments are of the wrong type, are out of acceptable range, or are
in
conflict with one another.

sFilter = "word LIKE ""%"" "
'Empty result set

sFilter = "word LIKE ""*"" "
'Empty result set rs.filter=sFilter

Yet when I try to query directly in Access...

SELECT vWords.Word
FROM vWords
WHERE word LIKE '*';

..it works fine and returns all records.

But this...

SELECT vWords.Word
FROM vWords
WHERE word LIKE '%';

,,,does not return any records
So I am confused about wild cards in Access with ADO.

Without going through complicated logic in the ASP page to test each
clause
to build one of several filter sets, how can I pass a wild card to return
all records for a certain condition?

IOW, how do I specify a filter that does this: WHERE word LIKE '*'; in my
ASP 30 page.


Feb 25 '07 #2
Thanks Bob. But any idea why it is not working?

As I tried to explain in the original post, this is a complex WHERE clause.
For subsequent conditions I can evaluate the criteria and either append them
with an AND or just leave them off. However, the first condition (in my
case "WHERE word LIKE") cannot start with an AND.

If I can use a wild card - like I believe I should be able to - it avoids a
lot of ASP code to evaluate all of the conditions necessary to determine
whether or not I need to append AND to my filter string.

With the time I have invested in this it would have been faster to just code
all the logic into the ASP.

But for my own edification, I would like to know why "rs.filter="word LIKE
'%'" does not work.

"Bob Lehmann" <no****@dontbotherme.zzzwrote in message
news:e%****************@TK2MSFTNGP03.phx.gbl...
>% is the correct wildcard for ADO.

Why don't you just leave out the LIKE clause entirely when you're not
filtering results?

SELECT vWords.Word
FROM vWords
WHERE word LIKE '*';

Is the same as

SELECT vWords.Word
FROM vWords
Bob Lehmann

"Dave" <da*******@newsgroup.nospamwrote in message
news:er*************@TK2MSFTNGP02.phx.gbl...
>[I posted this in the Access forum but the more I think of it, it's
probably
>more of an ADO issue since I can get it to work in Access but not ASP
30.]

I need to filter an Access 2000 result set in ASP 30 using the ADO
recordset.filter.

I build the filter in pieces. The first clause of the filter is this...

WHERE word LIKE 'S%'

.. to which other clauses are appended with AND.

This all works fine as long as I provide a condition for the first clause
(e.g., word LIKE 'S%').

However, if no condition is specified for the "Word LIKE" clause, I need
to
>pass a wild card and this is where I have a problem.

I tried constructing the following clauses and encountered the problems
indicated:

sFilter = "word LIKE '%' "
'Arguments are of the wrong type, are out of acceptable range, or are
in
>conflict with one another.

sFilter = "word LIKE '*' "
'Arguments are of the wrong type, are out of acceptable range, or are
in
>conflict with one another.

sFilter = "word LIKE ""%"" "
'Empty result set

sFilter = "word LIKE ""*"" "
'Empty result set rs.filter=sFilter

Yet when I try to query directly in Access...

SELECT vWords.Word
FROM vWords
WHERE word LIKE '*';

..it works fine and returns all records.

But this...

SELECT vWords.Word
FROM vWords
WHERE word LIKE '%';

,,,does not return any records
So I am confused about wild cards in Access with ADO.

Without going through complicated logic in the ASP page to test each
clause
>to build one of several filter sets, how can I pass a wild card to return
all records for a certain condition?

IOW, how do I specify a filter that does this: WHERE word LIKE '*'; in
my
ASP 30 page.



Feb 25 '07 #3
Dave wrote:
Thanks Bob. But any idea why it is not working?

As I tried to explain in the original post, this is a complex WHERE
clause. For subsequent conditions I can evaluate the criteria and
either append them with an AND or just leave them off. However, the
first condition (in my case "WHERE word LIKE") cannot start with an
AND.
There is an old hack that used "WHERE 1=1" as the beginning of each sql
statement being built this way for that very reason. It allows all
subsequest conditions to begin with the word "AND"

However, I don't recommend it. It's not really that hard to construct a
statement without resorting to this hack, no matter how complicated it is.
>
If I can use a wild card - like I believe I should be able to - it
avoids a lot of ASP code to evaluate all of the conditions necessary
to determine whether or not I need to append AND to my filter string.
Using LIKE with the wildcard as the first character in the comparison string
prevents the query engine from using an index: it has to scan every row. I
would prefer to write the extra code to make sure the query executes as
efficiently as possible. It's hard enough to use Access as an asp backend
without deliberately executing poorly performing sql statements.
With the time I have invested in this it would have been faster to
just code all the logic into the ASP.

But for my own edification, I would like to know why "rs.filter="word
LIKE '%'" does not work.

Wait a minute. Are you building a WHERE clause for a sql statement or
setting a recordset object's Filter property? These are two decidedly
different things. For example, with the Filter property, the first character
in the comparison string _cannot_ be a wild card - only the last.
--
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"
Feb 25 '07 #4
Okay so this is the issue:
with the Filter property, the first character in the comparison string
_cannot_ be a wild card - only the last.
So the syntax with ADO is more restrictive than with the native Access
(which will accept "word LIKE '*'")

I guess that's good to know athough I consulted a lot of sources on the use
of wildcards none of them warned on this limitation.

Thanks
Dave


"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcomwrote in message
news:OT**************@TK2MSFTNGP05.phx.gbl...
Dave wrote:
>Thanks Bob. But any idea why it is not working?

As I tried to explain in the original post, this is a complex WHERE
clause. For subsequent conditions I can evaluate the criteria and
either append them with an AND or just leave them off. However, the
first condition (in my case "WHERE word LIKE") cannot start with an
AND.

There is an old hack that used "WHERE 1=1" as the beginning of each sql
statement being built this way for that very reason. It allows all
subsequest conditions to begin with the word "AND"

However, I don't recommend it. It's not really that hard to construct a
statement without resorting to this hack, no matter how complicated it is.
>>
If I can use a wild card - like I believe I should be able to - it
avoids a lot of ASP code to evaluate all of the conditions necessary
to determine whether or not I need to append AND to my filter string.
Using LIKE with the wildcard as the first character in the comparison
string prevents the query engine from using an index: it has to scan every
row. I would prefer to write the extra code to make sure the query
executes as efficiently as possible. It's hard enough to use Access as an
asp backend without deliberately executing poorly performing sql
statements.
>With the time I have invested in this it would have been faster to
just code all the logic into the ASP.

But for my own edification, I would like to know why "rs.filter="word
LIKE '%'" does not work.

Wait a minute. Are you building a WHERE clause for a sql statement or
setting a recordset object's Filter property? These are two decidedly
different things. For example, with the Filter property, the first
character in the comparison string _cannot_ be a wild card - only the
last.
--
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"

Feb 26 '07 #5
Dave wrote:
Okay so this is the issue:
> with the Filter property, the first character in the comparison
string _cannot_ be a wild card - only the last.

So the syntax with ADO is more restrictive than with the native Access
(which will accept "word LIKE '*'")
First of all, let's get your terminology straight so you will be better
equipped to ask for help in the future:
it's not "native Access": it's "sql language". In particular, since you are
using an mdb file, the Jet database engine is used to manage it and the
varianat of sql used is called "JetSQL". All relational databases use some
variant of the sql language.

In addition, the use of the Filter property in web applications is highly
discouraged. Think about what has to happen in order for ADO to filter
records itself: it has to retrieve ALL the records in your database table,
pulling them across the network and building an inefficient recordset
container to hold them. Then, it applies the filter. Oh!, the records are
all still held in memory: ADO only "shows" you the records than meet the
filter criteria you set.

Now, look at the difference when using a sql statement to filter and
retrieve your records: the sql statement is sent to the database engine
(Jet) to be executed. The database engine analyzes the query and creates the
most efficient query plan it can come up with based on the query criteria
and the indexes you have built on the table to assist the database engine's
query optimizer. Using that plan, it quickly retrieves ONLY the records that
match the criteria and passes them to the client application (ADO). Less
network traffic, less memory resources consumed on the web server, less time
connected to the database, better chance to avoid the problems most people
encounter when using Jet as the backend for their web applications.

Again, it's hard enough to use Jet as your web application's backend without
deliberately doing things to make it work harder.
>
I guess that's good to know athough I consulted a lot of sources on
the use of wildcards none of them warned on this limitation.
:-)
Well, you must have skipped the ADO documentation
(http://msdn.microsoft.com/library/en...reference.asp).
This is well-documented here:
http://msdn.microsoft.com/library/en...b7a9be4c22.asp

I suspect they deliberately made the Filter property so restrictive in order
to discourage people from using it.

Further points to consider: most tutorials and books I've seen commit the
crime of teaching beginners to use dynamic sql. Sometimes, dynamic sql
cannot be avoided, but it should be the last tool drawn out of the tool
chest instead of the first. The major problem with dynamic sql is it leaves
web applications that use it vulnerable to hackers using a tchnique called
sql injection:

http://mvp.unixwiz.net/techtips/sql-injection.html
http://www.sqlsecurity.com/DesktopDefault.aspx?tabid=23

See here for a better, more secure way to execute your queries by using
parameter markers:
http://groups-beta.google.com/group/...e36562fee7804e

Personally, I prefer using stored procedures, or saved parameter queries
as
they are known in Access:

Access:
http://www.google.com/groups?hl=en&l...TNGP12.phx.gbl

http://groups.google.com/groups?hl=e...tngp13.phx.gbl
Bob Barrows
--
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"
Feb 26 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: DaveS | last post by:
Hello, I'm using Oracle 9.2 and would like to automatically save a copy of each deleted record in XML format to another database table. There...
4
by: Lucky | last post by:
I have a vb.net windows app that connects to an access database. The database has 1 table. One of the columns is called "Address". A user enters...
3
by: MasterChief | last post by:
I have a form that uses the POST method to call up test.asp and it passes what is typed into the text box. Since is uses the Like command the user...
5
by: Dan Hardy | last post by:
I am trying to search for a field where the wildcard needs to be in the field name i.e.: select * from userlist where fun??? = true order by...
1
by: deko | last post by:
I have a form where users can enter a string with asterisks to perform a wildcard search. Currently, the string entered by the user looks like...
2
by: Ken Yee | last post by:
First a little background: I've written an httphandler to handle wildcard extensions (i.e., I want to handle all URLs that come in rather than just...
10
by: Robert | last post by:
How do you get an accurate count of the number of records returned from a query when using linked tables. I have an access 2003 database as a...
8
by: Roland Hall | last post by:
In Access you use "*" + + "*", + can be replaced with & Calling a parameterized query in Access requires % be used in place of *, however, all...
0
by: savage678 | last post by:
Hi Everyone, I am new to this forum and am i dire need of some help. I am trying to use wildcard searches in infopath. I have it connected to an...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.