标题:求助,条件查询的结果在DataGrid中显示。
只看楼主
yeno
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-3-20
 问题点数:0 回复次数:1 
求助,条件查询的结果在DataGrid中显示。
两个OptionButton控件,两个ComboBox控件,一个DataGrid控件,如何通过选择OptionButton后,再选择与之对应的ComboBox里的内容后,把查询的结果在DataGrid里显示出来。代码如何写?急......
搜索更多相关主题的帖子: DataGrid 条件 结果 控件 ComboBox 
2008-03-20 14:26
yeno
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-3-20
得分:0 
三个OptionButton,optionButton1对应text7,optionButton2对应text8,optionButton3对应text9
Dim sql As String
    Dim rs As New ADODB.Recordset
    Dim conn As New ADODB.Connection
    conn.Open "provider=Microsoft.Jet.OLEDB.4.0; data source=" & App.Path & "\db1.mdb"
   
    If Option1.Value = True And Text7.Text <> "" Then
       Text8.Text = ""
        Text8.Text = ""
        sql = "select * from Attendence where ENo='" & Text7.Text & "'"
    ElseIf Option1.Value = True And Text7.Text = "" Then
        MsgBox "请输入要查询的员工编号!", vbOKOnly + vbExclamation
        Text7.SetFocus
        
    End If
   
    If Option2.Value = True And Text8.Text <> "" Then
       Text7.Text = ""
        Text9.Text = ""
        sql = "select * from Attendence where Name='" & Text8.Text & "'"
    ElseIf Option2.Value = True And Text8.Text = "" Then
   
        MsgBox "请输入要查询的员工编号!", vbOKOnly + vbExclamation
        Text8.SetFocus
        
    End If
   
     If Option3.Value = True And Text9.Text <> "" Then
        Text7.Text = ""
        Text8.Text = ""
        sql = "select * from Attendence where DeptID=" & Val(Text9.Text)
    ElseIf Option3.Value = True And Text9.Text = "" Then
        MsgBox "请输入要查询的员工编号!", vbOKOnly + vbExclamation
        Text9.SetFocus
      
        
    End If
   
    rs.CursorLocation = adUseClient
    rs.Open sql, conn, adOpenKeyset, adLockPessimistic
     With DataGrid1
            .AllowAddNew = False
            .AllowDelete = False
            .AllowUpdate = False
      End With
      Set DataGrid1.DataSource = rs
2008-03-23 19:06



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-204387-1-1.html




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

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