组合查询


Private Sub cmdInquire_Click()
    Dim mrc As ADODB.Recordset
    Dim msgText As String
    Dim txtSQL As String
    txtSQL = "select cardno,studentno,studentname,sex,department,grade,class,cash,status,comment from student_info where "
    If Testtxt(cmbFields(0).Text) Then
        MsgBox "请选择字段名", vbOKOnly + vbExclamation, "学生基本信息维护"
        cmbFields(0).SetFocus
        Exit Sub
    Else
        txtfields = ChangedString(cmbFields(0).Text)
    End If
    If Testtxt(cmbOperators(0).Text) Then
        MsgBox "请选择操作符", vbOKOnly + vbExclamation, "学生基本信息维护"
        cmbOperators(0).SetFocus
        Exit Sub
    End If
    If Testtxt(txtContent(0).Text) Then
        MsgBox "请添写要查询的内容", vbOKOnly + vbExclamation, "学生信息管理系统"
        txtContent(0).SetFocus
        Exit Sub
    End If
        txtSQL = txtSQL & "" & txtfields & " " & cmbOperators(0).Text & " '" & txtContent(0).Text & " '"
    If Testtxt(Trim(cmbOrAnd(0).Text)) = False Then
        txtfields = ChangedString(cmbOrAnd(0).Text)
        txtSQL = txtSQL & " " & txtfields & ""
        If Testtxt(cmbFields(1).Text) Then
            MsgBox "请选择字段名", vbOKOnly + vbExclamation, "学生基本信息维护"
            cmbFields(1).SetFocus
            Exit Sub
        Else
            txtfields = ChangedString(cmbFields(1))
            
        End If
        If Testtxt(cmbOperators(1).Text) Then
            MsgBox "请选择操作符", vbOKOnly + vbExclamation, "学生基本信息维护"
            cmbOperators(1).SetFocus
            Exit Sub
        End If
        If Testtxt(txtContent(1).Text) Then
            MsgBox "请添写要查询的内容", vbOKOnly + vbExclamation, "学生信息管理系统"
            txtContent(1).SetFocus
            Exit Sub
        End If
        txtSQL = txtSQL & " " & txtfields & " " & cmbOperators(0).Text & "'" & txtContent(1).Text & "'"
    End If
    If Testtxt(cmbOrAnd(1).Text) = False Then
        txtfields = ChangedString(cmbOrAnd(1).Text)
        txtSQL = txtSQL & "" & txtfields & ""
        If Testtxt(cmbFields(2).Text) Then
            MsgBox "请选择字段名", vbOKOnly + vbExclamation, "学生基本信息维护"
            cmbFields(2).SetFocus
            Exit Sub
        Else
            txtfields = ChangedString(cmbFields(2).Text)
        End If
        If Testtxt(cmbOperators(2).Text) Then
            MsgBox "请选择操作符", vbOKOnly + vbExclamation, "学生基本信息维护"
            cmbOperators(2).SetFocus
            Exit Sub
        End If
        If Testtxt(txtContent(2).Text) Then
            MsgBox "请添写要查询的内容", vbOKOnly + vbExclamation, "学生信息管理系统"
            txtContent(0).SetFocus
            Exit Sub
        End If
        txtSQL = txtSQL & " " & txtfields & "" & cmbOperators(2).Text & " '" & txtContent(2).Text & "'"
    End If
    Set mrc = ExecuteSQL(txtSQL, msgText)
    With FlexGridSt
        .Rows = 1
        .Cols = 10
        .TextMatrix(0, 0) = "卡号"
        .ColWidth(0) = 1800
        .TextMatrix(0, 1) = "学号"
        .ColWidth(1) = 1800
        .TextMatrix(0, 2) = "姓名"
        .TextMatrix(0, 3) = "性别"
        .TextMatrix(0, 4) = "系别"
        .ColWidth(4) = 1800
        .TextMatrix(0, 5) = "年级"
        .TextMatrix(0, 6) = "班级"
        .TextMatrix(0, 7) = "金额"
        .TextMatrix(0, 8) = "状态"
        .ColWidth(8) = 1800
        .TextMatrix(0, 9) = "备注"
        
        Do While Not mrc.EOF
            .Rows = .Rows + 1
            For i = 0 To 9
                 .TextMatrix(.Rows - 1, i) = mrc.Fields(i)
            Next i
            mrc.MoveNext
        Loop
    End With
End Sub


评论 17
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值