Avatar of sanlorenzo
sanlorenzo
 asked on

Visual Studio Query

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
System ProgrammingMicrosoft DevelopmentVisual Basic.NET

Avatar of undefined
Last Comment
sanlorenzo

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
AndyAinscow

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
QuinnDex

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

sanlorenzo

ASKER
Yes  thanks , this is a Typing Mistake , done while i typed the question

the SQL  on the Application is correct
sanlorenzo

ASKER
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
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
AndyAinscow

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)?
sanlorenzo

ASKER
don't yiou think that some can do a mistake ??/ you may send agoin the answer , obviousily i will accept
AndyAinscow

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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
sanlorenzo

ASKER
Thanks Mr South

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