| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 390 人关注过本帖
标题:帮帮忙~~~~~~~~~~~~~~~~
只看楼主 加入收藏
longwindwind
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2005-11-7
收藏
 问题点数:0 回复次数:4 
帮帮忙~~~~~~~~~~~~~~~~

帮忙看一下,我想作一个查询复合多条条件的记录,我这样写总是查不出来,怎么改能改成查出复合多个条件的记录
Dim mysql As String
mysql = "select * from s where sno is not null"
If Check1.Value Then
mysql = mysql & " and sno='" & Text2.Text & "' "

If Check2.Value Then
mysql = mysql & " and sn='" & Text3.Text & "' "

If Check3.Value Then
mysql = mysql & " and sex='" & Text4.Text & "' "

If Check4.Value Then
mysql = mysql & " and age=" & Text5.Text & " "

If Check5.Value Then
mysql = mysql & " and dept='" & Text6.Text & "' "

If Check6.Value Then
mysql = mysql & " and nn='" & Text7.Text & "' "

End If
End If
End If
End If
End If
End If
Set i = New ADODB.Connection
Set j = New ADODB.Recordset
i.ConnectionString = "provider=sqloledb.1;data source=(local);user id=sa;pwd=247162545;initial catalog=sdb"
i.Open
j.Open mysql, i, adOpenDynamic, adLockOptimistic
Set MSHFlexGrid1.DataSource = j
Text8.Text = mysql

2005-11-08 13:55
zmjls
Rank: 1
等 级:新手上路
帖 子:377
专家分:0
注 册:2005-9-30
收藏
得分:0 
判断语句不规范,把它改成IF嵌套语句!!

对ASP、.NET、SQL情有独钟的情圣王子! 俺目标:睡觉睡到自然醒数钱数到手抽筋!
2005-11-08 17:04
syh878
Rank: 1
等 级:新手上路
威 望:2
帖 子:461
专家分:0
注 册:2005-9-2
收藏
得分:0 
Dim mysql As String
mysql = "select * from s where sno is not null"
If Check1.Value Then mysql = mysql & " and sno='" & Text2.Text & "' "

If Check2.Value Then mysql = mysql & " and sn='" & Text3.Text & "' "

If Check3.Value Then mysql = mysql & " and sex='" & Text4.Text & "' "

If Check4.Value Then mysql = mysql & " and age=" & Text5.Text & " "

If Check5.Value Then mysql = mysql & " and dept='" & Text6.Text & "' "

If Check6.Value Then mysql = mysql & " and nn='" & Text7.Text & "' "


2005-11-09 14:28
syh878
Rank: 1
等 级:新手上路
威 望:2
帖 子:461
专家分:0
注 册:2005-9-2
收藏
得分:0 

可以把checkbox改为数组,然后用select,这样方便


2005-11-09 14:32
longwindwind
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2005-11-7
收藏
得分:0 

哦,谢谢~~

2005-11-09 18:18
快速回复:帮帮忙~~~~~~~~~~~~~~~~
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017334 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved