如何在c#中使用多数据搜索来搜索记录 [英] How to search record using multidata search in c#
本文介绍了如何在c#中使用多数据搜索来搜索记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用多数据搜索搜索记录
我有三个数据来搜索记录
类
部分
流
例如
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
但如果One值缺失
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???
推荐答案
put与一起查询和检查空列
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 ";
先生,尝试让你的查询有点动态
例如。访问尝试此代码
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"";
对于您的要求,您可能需要构建动态查询
For ur requirement you may need to build dynamic query
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
这篇关于如何在c#中使用多数据搜索来搜索记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文