473,403 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

LIKE clause bug in ASP.NET?

I am trying to get a handful of records returned via the following query
using a datareader and then binding it to a datagrid:

Select * from documents WHERE (title LIKE '*network*') Order By department,
headername, title;

It keeps returning 0 records. Note that if I take out the crieteria for the
LIKE clause, it returns just fine. If I copy and paste this into a query
within the database itself, if works fine! Why will asp.net not return the
records? I have tried formatting it in a million different ways. All of
which work directly in the database, buy none when I try to go through the
datareader.

Any suggestions? Known bugs? Anything?
Nov 19 '05 #1
4 1192
Rick Csucsai wrote:
I am trying to get a handful of records returned via the following
query using a datareader and then binding it to a datagrid:

Select * from documents WHERE (title LIKE '*network*') Order By
department, headername, title;

It keeps returning 0 records. Note that if I take out the crieteria
for the LIKE clause, it returns just fine. If I copy and paste this
into a query within the database itself, if works fine! Why will
asp.net not return the records? I have tried formatting it in a
million different ways. All of which work directly in the database,
buy none when I try to go through the datareader.

Any suggestions? Known bugs? Anything?


Try
Select * from documents WHERE (title LIKE '%network%')

The usual wildcard in SQL is a %, not a *. If you run the query
in Access, you need the "*". If you run it through a middle layer,
that layer wants regular SQL which it will translate into the db-specific
syntax.
By the way: the "single character" wildcard in SQL is "_" (not "?").

Hans Kesting
Nov 19 '05 #2
Rick Csucsai wrote:
I am trying to get a handful of records returned via the following
query using a datareader and then binding it to a datagrid:

Select * from documents WHERE (title LIKE '*network*') Order By
department, headername, title;


I assume you are using Access ...

When using ADO.Net to execute queries, you need to use the ODBC wildcards
(?, _) instead of the Jet wildcards (*, ?)

WHERE title LIKE '%network%'

HTH,
Bob Barrows

PS. You should avoid using selstar in production code:
http://www.aspfaq.com/show.asp?id=2096

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Nov 19 '05 #3
Yep, you were right. Replaced the "*" with "%" and it worked fine.
Ironically, putting the syntax direct in Access now returns 0 records but in
the code works fine

go figure...

Thanks guys!

Rick
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:u3**************@TK2MSFTNGP09.phx.gbl...
Rick Csucsai wrote:
I am trying to get a handful of records returned via the following
query using a datareader and then binding it to a datagrid:

Select * from documents WHERE (title LIKE '*network*') Order By
department, headername, title;


I assume you are using Access ...

When using ADO.Net to execute queries, you need to use the ODBC wildcards
(?, _) instead of the Jet wildcards (*, ?)

WHERE title LIKE '%network%'

HTH,
Bob Barrows

PS. You should avoid using selstar in production code:
http://www.aspfaq.com/show.asp?id=2096

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Nov 19 '05 #4
Just to reiterate what Hans said:
When running it in Access, you have to use the Jet wildcards. Access passes
the query directly to Jet - neither OLE DB nor ODBC is involved.

When running it via ADO/ADO.Net, you have to use the ODBC wildcards. When
the Jet OLE DB Provider (or ODBC driver if you are using ODBC) parses the
query, it replaces the ODBC wildcards with the Jet wildcards before passing
it along to Jet to be executed. When the query already contains an asterisk,
the Jet Provider escapes it so it is treated as a literal character rather
than a wildcard.

Bob Barrows
Rick Csucsai wrote:
Yep, you were right. Replaced the "*" with "%" and it worked fine.
Ironically, putting the syntax direct in Access now returns 0 records
but in the code works fine


--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Nov 19 '05 #5

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

Similar topics

105
by: Peter Hickman | last post by:
Well after all this discussion it would appear that a 'Python like' language has appeared => Prothon. http://www.prothon.org/index.html Very alpha, sort of like Python (if you consider the...
4
by: Tom Walker | last post by:
I cannot get the WHERE statement to work correctly unless I use a literal with the LIKE. I want to use a working storage data name so that I can vary the WHERE statement. Example that works: ...
1
by: Kerr | last post by:
Hi all, I am writing a simple app to query a microsoft access 2000 databse in asp.net. Nothing complicated, but I am writing some inline SQL to query a table with a LIKE clause in it (i.e....
2
by: Michael C | last post by:
Hi all. When I run the following query against my Access database - from within Access - it returns the correct results (5 records in this instance): SELECT * FROM WHERE = "Clothes" AND LIKE...
26
by: GreatAlterEgo | last post by:
Hi, This is my query which is embedded in a COBOL program. EXEC SQL SELECT DATE, AGE, DURATION, AMT INTO :LDATE, :L.AGE, :L.DURATION, :L.AMT FROM TAB1 WHERE CODE = :KEY.CODE AND...
7
by: Mike Charney | last post by:
Can anyone tell me why the following statement doesnt work? DoCmd.OpenForm "frmSearchResults", , , "text24 Like *" & filter1 & "*" Field text24 is the field on teh results form that I am trying...
5
by: davehansen22 | last post by:
Is there a way to generate a MySQL WHERE clause from a search string like this: "(dave OR hansen) php programmer" I would want to use the generated MySQL clause against a "memo" type field. ...
5
by: pwiegers | last post by:
Hi, I'm trying to use the result of a conditional statement in a where clause, but i'm getting 1)nowhere 2) desperate :-) The query is simple: -------- SELECT idUser,...
1
by: john | last post by:
I'm trying to build a LINQ expression that will use a dynamic construction of a LIKE statement in the WHERE clause, it would look something like this in SQL: WHERE TaskGroup Like "*00*" OR...
5
by: nidaar | last post by:
From a security point of view, is accepting wildcards like "%" in input parameters of stored procedures against any best practices? As an example, if a user defined function uses "Productname...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.