Solved

Visual Studio Query

Posted on 2013-12-01
9
382 Views
Last Modified: 2013-12-05
I have a Visual Studio Form Called Form1

It is conencted to the Query_BuilderDataSet1  which retrive data from a Table tbl_Resources

On the Form1 i have the Grid from the Data set   with contains the collumn ID_Resource , Name , Region, Town , Employer

From the Table adpter tbl_ResourceTableAdpter i have Open the Query Bulder  and design a Query : SELECT ID_Resources , Name , Region , Town , Employer
FROM tbl_Resources
WHERE (Region=@Region OR @Region IS NULL ) AND (Emplyer =@Employer OR @Employer IS NULL )

For example i have inserted IS NULL thinking to have the possibility to Optionally insert only one of the 2 Parameters

But it is Not Working ,

When i Go on the Form1 and  Fill only one of the 2 Text Box  created by the VS designer

the Return into the Grid on Form1 is an Empty Grid

Any one that can help to write the SQL code or the Visual Basic code  behing the Form1 to handle the Opition to have declared only 1 of the 2 Crtieria

For Clarity i have also u Button that  on Click will remove the Query and will show again all the records

Thanks fro Help
0
Comment
Question by:sanlorenzo
  • 4
  • 3
9 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 39688008
Have you checked the parameters you actually pass in ?
The empty string "" is not the same as the value NULL
0
 
LVL 9

Expert Comment

by:QuinnDex
ID: 39688013
you have a typo in this line

WHERE (Region=@Region OR @Region IS NULL ) AND (Emplyer =@Employer OR @Employer IS NULL )


it should read

WHERE (Region=@Region OR @Region IS NULL ) AND (Employer =@Employer OR @Employer IS NULL ) 

Open in new window

0
 

Author Comment

by:sanlorenzo
ID: 39689168
Yes  thanks , this is a Typing Mistake , done while i typed the question

the SQL  on the Application is correct
0
 

Author Comment

by:sanlorenzo
ID: 39689170
Ok  , i see SQL is not correct   IS NULL is not the best  when i have to deal with Empty String

so  what do you suggest as a solution ?? Thanks
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39689177
Ermm.  Why did you accept the comment from the other expert despite you saying it isn't correct AND pointing out my comment was relevant (correct)?
0
 

Author Comment

by:sanlorenzo
ID: 39689181
don't yiou think that some can do a mistake ??/ you may send agoin the answer , obviousily i will accept
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39689209
Repeat of earlier comment:
Have you checked the parameters you actually pass in ?
The empty string "" is not the same as the value NULL

And to check for an empty string a simple modification is required
(Region=@Region OR @Region IS NULL )
should be
((Region=@Region) OR (@Region IS NULL) OR (@Region=''))
where the '' are two single quote marks (it might require double quotes, some SQL can be fussy) and similarly for any other checks in the where clause.

ps.  I like using lots of brackets, it might not be necessary but it makes it much easier to read the logic.


pps.  I really do mean check what your parameter values are, if you are really passing null into the query then this comment is also not the solution to your problem.
0
 

Author Comment

by:sanlorenzo
ID: 39700222
Thanks Mr South

sorry , i did not accept my self , have good day
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
WPF - Tooltips for ComboBox items 5 40
More on Time zones in vb 2010 12 37
SQL syntax in VB.net 5 30
I need help making a collection from a class in VB.Net 3 27
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now