| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 385 人关注过本帖, 1 人收藏
标题:请教大家问题,谢谢啦
只看楼主 加入收藏
Bendis
Rank: 1
来 自:福建厦门
等 级:新手上路
帖 子:47
专家分:0
注 册:2010-4-2
结帖率:93.75%
收藏(1)
已结贴  问题点数:10 回复次数:2 
请教大家问题,谢谢啦
Private Sub Command1_Click()
Dim aa As Integer
 txtsql = ""
If Trim(Text1(0).Text) <> "" Then
  aa = 1
  If txtsql = "" Then                                      这边的txtsql是什么作用,有定义全局变量,帮忙看看
    txtsql = "xj.学号='" & Trim(Text1(0).Text) & "'"
  Else
    txtsql = txtsql & "and xj.学号='" & Trim(Text1(0).Text) & "'"
  End If
End If
If Trim(Text1(1).Text) <> "" Then
aa = 1                                                      这边的aa是什么作用,也帮忙看看
  If txtsql = "" Then
    txtsql = "xj.姓名='" & Trim(Text1(1).Text) & "'"
  Else
    txtsql = txtsql & "and xj.姓名='" & Trim(Text1(1).Text) & "'"
  End If
End If
If Trim(Text1(2).Text) <> "" Then
  aa = 1
  If txtsql = "" Then
    txtsql = "xj.班级='" & Trim(Text1(2).Text) & "'"
  Else
    txtsql = txtsql & "and xj.班级='" & Trim(Text1(2).Text) & "'"
  End If
End If
If Trim(Text1(3).Text) <> "" Then
 aa = 1
 txtsql = ""
txtsql = "xj.姓名 like '%" & Trim(Text1(3).Text) & "%'"

End If
If aa = 0 Then
  ss = MsgBox("你至少要输入一个条件以上才能查询!", , " 警告")
  Text1(0).SetFocus
  Exit Sub
  
End If
搜索更多相关主题的帖子: Text1 
2010-05-12 10:21
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4943
专家分:30067
注 册:2008-10-15
收藏
得分:10 
aa  标记 是否有条件查询,只要有一个条件,那么 aa=1  ,否则 aa=0
依次在各个条件段中进行赋值.

txtsql 是组合的查询条件变量

If Trim(Text1(0).Text) <> "" Then                                          '内容不为空
  aa = 1                       '设置有条件
  If txtsql = "" Then                       '原查询条件为空               
    txtsql = "xj.学号='" & Trim(Text1(0).Text) & "'"        '直接生成查询条件
  Else '否则
    txtsql = txtsql & "and xj.学号='" & Trim(Text1(0).Text) & "'"       '加上面的条件,再生成查询条件
  End If
End If


授人于鱼,不如授人于渔
早已停用QQ了
2010-05-12 10:37
Bendis
Rank: 1
来 自:福建厦门
等 级:新手上路
帖 子:47
专家分:0
注 册:2010-4-2
收藏
得分:0 
高手,一语惊醒,谢谢啊
2010-05-12 10:46
快速回复:请教大家问题,谢谢啦
数据加载中...
 
   



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

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