Click here to Skip to main content
15,920,217 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to search record using multidata search

I have three data to search a record
Class
Section
Stream


For Exampale
"Select * from tb_StudentInfo where Class="Value" and Section="Value" and Stream="Value"";
this query return correct value



But if One value missing
"Select * from tb_StudentInfo where Class="Value" and Section="null" and Stream="null"";

query return nothing

How to solve this problem???
Posted
Updated 13-May-14 0:18am
v2

put the query like and check null column with is null
"Select * from tb_StudentInfo where Class="Value" and Section is null  and Stream is null ";  
 
Share this answer
 
Comments
Manamohan Jha 13-May-14 6:29am    
how to set "is null" on runtime???
Manamohan Jha 13-May-14 6:30am    
Query not working with Access Databse???
[no name] 13-May-14 6:35am    
Write a store procedure check with null condition
if(@Section is null and @Stream is null)
{ "Select * from tb_StudentInfo where Class="Value" and Section is null and Stream is null "; }
sir, try making your query a little dynamic

For eg. for access try this code
"Select * from tb_StudentInfo 
where Class=' & Value & '
 iif(IsNull('Your value')=false,' and Section=' & value,'') & 
 and iif(IsNull('Your value')=false,' and Stream=' & value,'')";


in the above example it will search if the value is null the query becomes this
"Select * from tb_StudentInfo where Class="Value"";
 
Share this answer
 
For ur requirement you may need to build dynamic query

C#
string query="Select * from tb_StudentInfo ";

if(Class!=null&&Section!=null&&Stream!=null)
{
query=query+"where Class="Value" and Section="Value" and Stream="Value"";
}
else if(Section==null&&Stream==null)
{
query=query+"where  Class="Value"";
}
else if(Class==null&&Stream==null)
{
query=query+"where Section="Value"";
}
else if(Class==null&&Section==null)
{
query=query+"where Stream="Value"";
}
else if(Class==null)
{
query=query+"where Section="Value" and Stream="Value"";
}
else if(Section==null)
{
query=query+"where Class="Value" and Stream="Value"";
}
else if(Stream==null)
{
query=query+"where Section="Value" and Class="Value"";
}

Now you can use query variable
 
Share this answer
 
v2
Comments
Manamohan Jha 13-May-14 6:46am    
I know this idea, its to long
Please give me short idea???

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900