如题!~
以下是代码!~
Private Sub Command1_Click()
Dim rst As New ADODB.Recordset
Dim StrSql As String
Dim ArrIndex As Variant
ArrIndex = Array("student_id", "student_name", "sex", "nathionality", "familiy_place", "class_id", "pro_id")
If Option1.Value = True Then
StrSql = "select * from students where " & ArrIndex(Combo1.ListIndex) & "='" & Text1.Text & "'"
Set rst = QueryExt(StrSql)
ElseIf Option2.Value = True Then
StrSql = "select * from students where " & ArrIndex(Combo1.ListIndex) & "='" & Text1.Text & "' and " & ArrIndex(Combo2.ListIndex) & "='" & Text2.Text & "'"
Set rst = QueryExt(StrSql)
End If
If rst.EOF = True Then
MsgBox "没有满足条件的学生,请确认输入的查询内容正确!~"
Text1.SetFocus
Exit Sub
End If
Set MSH1.DataSource = rst.DataSource '在这里负值数据源就会出错,可是在下面却可以!~
MSH1.Refresh
End Sub
Private Sub Form_Load()
Dim rst As New ADODB.Recordset
Dim StrSql As String
StrSql = "select * from students"
Set rst = QueryExt(StrSql)
Set MSH1.DataSource = rst.DataSource '在这里也是负值,但不会出错!~
MSH1.Refresh
Set rst = Nothing
Combo1.AddItem "学号"
Combo1.AddItem "姓名"
Combo1.AddItem "性别"
Combo1.AddItem "民族"
Combo1.AddItem "籍贯"
Combo1.AddItem "所在学院"
Combo1.AddItem "所在专业"
Combo2.AddItem "学号"
Combo2.AddItem "姓名"
Combo2.AddItem "性别"
Combo2.AddItem "民族"
Combo2.AddItem "籍贯"
Combo2.AddItem "所在学院"
Combo2.AddItem "所在专业"
Combo1.ListIndex = 0
Combo2.ListIndex = 0
Text1.Text = ""
Text2.Text = ""
Combo1.Enabled = False
Combo2.Enabled = False
Text1.Enabled = False
Text2.Enabled = False
End Sub
Private Sub Option1_Click()
If Option1.Value = True Then
Combo1.Enabled = True
Text1.Enabled = True
Combo2.Enabled = False
Text2.Enabled = False
Text1.SetFocus
Else
Combo1.Enabled = False
Text1.Enabled = False
End If
End Sub
Private Sub Option2_Click()
If Option2.Value = True Then
Text1.SetFocus
Combo2.Enabled = True
Text2.Enabled = True
Else
Combo2.Enabled = False
Text2.Enabled = False
End If
End Sub