机房收费系统--组合查询

在学生信息管理系统中我们用到了组合查询,就是通过用check项,将SQL 语句一点点完善,
最后在数据库中查询。
机房收费--组合查询 - 十一期 张峰 - 张峰 廊坊师范学院信息技术提高班 十一期
 机房收费系统中同样用到了组合查询,差别是提供字段让我们选择,还有就是用到了“and”和“or ”来组合
  机房收费--组合查询 - 十一期 张峰 - 张峰 廊坊师范学院信息技术提高班 十一期
 这里我们引入了comboBox.Tag 属性。用comboBox.Tag来代替选择的字段名。
代码如下:
第一步:将选择的字段名用数据库中的字段代替。
Private Sub Combo1_Change()
If cmbField1.Text = "教师" Then cmbField1.Tag = "UserID"
If cmbField1.Text = "注册日期" Then cmbField1.Tag = "LoginDate"
If cmbField1.Text = "注册时间" Then cmbField1.Tag = "LoginTime"
If cmbField1.Text = "注销日期" Then cmbField1.Tag = "LogoutDate"
If cmbField1.Text = "注销时间 " Then cmbField1.Tag = "LogoutTime"
If cmbField1.Text = "机器号" Then cmbField1.Tag = "computer"
End Sub

Private Sub cmbMode2_Click()
If cmbMode2.Text = "与" Then cmbMode2.Tag = "and"
If cmbMode2.Text = "或" Then cmbMode2.Tag = "or "
End Sub
第二部:编写SQL查询代码,一点点完善
例如:(select * from worklog_Info where ****order by serial)
Private Sub cmdInquiry_Click()
Dim txtSQL As String
Dim MsgText As String
Dim mrc As ADODB.Recordset
    txtSQL = "select * from worklog_Info where (" & cmbField1.Tag & cmbSign1.Text & " '" & txtInquire1.Text & "'"
     If cmbMode2.Text <> "" Then
         If cmbField2.Text = "" Then
            MsgBox "请选择字段名!", vbOKOnly + vbExclamation, "警告"
            cmbField2.SetFocus
            Exit Sub
         End If
         If cmbSign2.Text = "" Then
             MsgBox "请选择操作符!", vbOKOnly + vbExclamation, "警告"
             cmbSign2.SetFocus
             Exit Sub
         End If
         If txtInquire2.Text = "" Then
             MsgBox "请输入要查询的内容!", vbOKOnly + vbExclamation, "警告"
             txtInquire2.SetFocus
             Exit Sub
         End If
      txtSQL = txtSQL & " " & cmbMode2.Tag & " " & cmbField2.Tag & cmbSign2.Text & " '" & txtInquire2.Text & "'"
   End If
      If cmbMode3.Text <> "" Then
         If cmbField3.Text = "" Then
            MsgBox "请输入字段名!", vbOKOnly + vbExclamation, "警告"
            cmbField3.SetFocus
            Exit Sub
         End If
         If cmbSign3.Text = "" Then
            MsgBox "a请输入操作符!", vbOKOnly + vbExclamation, "警告"
            cmbSign3.SetFocus
            Exit Sub
         End If
         If txtInquire3.Text = "" Then
            MsgBox "请输入要查询的内容!", vbOKOnly + vbExclamation, "警告"
            txtInquire3.SetFocus
            Exit Sub
         End If
      txtSQL = txtSQL & " " & cmbMode3.Tag & " " & cmbField3.Tag & cmbSign3.Text & " ' " & txtInquire3.Text & " '"
   End If
      txtSQL = txtSQL & ") order by serial"
      Set mrc = ExecuteSQL(txtSQL, MsgText)
    If mrc.RecordCount = 0 Then
         myFlexGrid.Clear
          MsgBox "结果集为空!", vbOKOnly + vbExclamation, "警告"
          Exit Sub
       End If
       
       

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 14
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值