请各位给一个多条件查询的好算法好吗。。

liangivw 2006-09-16 09:00:55
例如:

条件1 textbox1
条件2 textbox2
条件3 textbox3

按查询时可以按各个条件查,他们可以独立查询也可以组合查询,比如,按条件1查询时查出条件1的数据,如此类推,如果按条件1,2,3组合查询时可以查出符合三个条件的数据,还有时它们可能会有为空的时候,
除了用多重判断之外还可以有什么算法可以比较好啊,因为多重判断很类锁,而且容易出错。
...全文
125 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
liangivw 2006-09-16
  • 打赏
  • 举报
回复
谢谢各位帮忙,我先试试
yunxiao_2004 2006-09-16
  • 打赏
  • 举报
回复
string strSQL ="select * from tb where 1=1 "

if (textbox1.text.Trim()!="")
strSQL += string.format(" and fld1 ='{0}'", textbox1.text);
if (textbox2.text.Trim()!="")
strSQL += string.format(" and fld2 ='{0}'", textbox2.text);
if (textbox3.text.Trim()!="")
strSQL += string.format(" and fld3 ='{0}'", textbox3.text);
何必还要什么 s1, s2 ,s3 干什么呢!!
vbman2003 2006-09-16
  • 打赏
  • 举报
回复
上面错了

dim sql as string ="select * from tb where 1=1 "
dim s1 as string = ""
dim s2 as string = ""
dim s3 as string = ""

if not (textbox1.text="") then s1 = " and fld1 ='"& textbox1.text &"'"
if not (textbox2.text="") then s2 = " and fld2 ='"& textbox2.text &"'"
if not (textbox3.text="") then s3 = " and fld3 ='"& textbox3.text &"'"

sql = sql & s1 & s2 & s3
vbman2003 2006-09-16
  • 打赏
  • 举报
回复
dim sql as string ="select * from tb where 1=1 "
dim s1 as string = ""
dim s2 as string = ""
dim s3 as string = ""

if not (textbox1.text="") then s1 = " and fld1 ='"& textbox1.text &"'"
if not (textbox2.text="") then s1 = " and fld2 ='"& textbox2.text &"'"
if not (textbox3.text="") then s1 = " and fld3 ='"& textbox3.text &"'"

sql = sql & s1 & s2 & s3

是不是这个?


62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧