Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 21st, 2004, 08:24 PM
Registered User
 
Join Date: Mar 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to programmer_kay
Default Wildcard characters in query giving trouble

Hi,

I am using the following type of query:

"SELECT mouseid from mousedata where (gene1 like '" & gene1 & "' or gene1 is null)"

where gene1 is appended by %(wildcard) in the following way:
gene1=string.concat(gene1,"%")

My problem is when I use this query and enter some value for gene1 I get all records having that value and also all records having null.
If I remove the is null criteria then I do not get the null fields when I leave the search criteria blank which I want.

I thought a wildcard like % will take any value. But it doesnt take NULL.
I looked into it and tried using the NZ function in acces. It works well when the query is directly written in access but gives oledb error in visual basic.net
Thanks

 
Old March 21st, 2004, 08:28 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Can you explain what you want your search to return? I'm a little confused by your post. It sounds like you are looking for "give me all rows that contain my search string, or if no search string, give me the null rows". Is this what you want?
 
Old March 21st, 2004, 08:32 PM
Registered User
 
Join Date: Mar 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to programmer_kay
Default

Search should bve like

"give me all rows that contain my search string, or if no search string, give me the all rows in the table including rows having null".
Thanks for your concern
 
Old March 21st, 2004, 10:04 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I think your best bet is to use two different queries. One for when you have search criteria and one when you don't.

For the "all rows" query, you don't need anything special at all:
"SELECT mouseid from mousedata"

The search query will need to look like this:
"SELECT mouseid from mousedata where gene1 like '%" & gene1 & "%'"
or better still...
String.Format("SELECT mouseid from mousedata where gene1 like '%{0}%'", gene1)

Peter
------------------------------------------------------
Work smarter, not harder.





Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL query on Access db giving error DesignsOnline.co.uk Access 2 November 17th, 2006 05:06 PM
SQL count query not giving correct results hman SQL Language 2 March 16th, 2005 07:06 AM
SQL count query not giving correct results hman SQL Server 2000 1 March 15th, 2005 01:15 PM
ADO Query kills the Wildcard in LIKE stmt Vanaj Access 2 April 1st, 2004 11:31 AM
Nested Query Trouble ashley_y VB How-To 1 December 23rd, 2003 05:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.