vb adodc 控件的问题

来源:百度知道 编辑:UC知道 时间:2024/05/12 00:58:46
界面有两个COMBO控件,combo1是存放字段名称的,combo2存放字段值
代码如下:
Private Sub Form_Load() '载入时把字段名添加到combo1中
Adodc1.RecordSource = "select * from 基本信息"
Adodc1.Refresh
Combo1.Clear
Dim i
For i = 0 To Adodc1.Recordset.Fields.Count - 1
Combo1.AddItem Adodc1.Recordset.Fields(i).Name
Next i
Combo1.Text = Combo1.List(0)
End Sub

Private Sub Combo1_click() '在combo1中选择字段名,combo2中把所有该字段中的值列出来
Adodc1.RecordSource = "select * from 基本信息"
Adodc1.Refresh
Combo2.Clear
While Not Adodc1.Recordset.EOF
Combo2.AddItem Adodc1.Recordset.Fields(Combo1.Text)
Adodc1.Recordset.MoveNext
Wend
Combo2.Text = Combo2.List(0)
End Sub

Private Sub Combo2_click()
Dim c
c = Trim(Combo1.Text)
If Adodc1.Recordset.Fields(c).Type = 202 Then
Adodc1.RecordSource = "select * from 基本信息 where" & c & "='" & Combo2.Text & "'"
Else

你的where 和字段之间没有空格将
If Adodc1.Recordset.Fields(c).Type = 202 Then
Adodc1.RecordSource = "select * from 基本信息 where" & c & "='" & Combo2.Text & "'"
Else
Adodc1.RecordSource = "select * from 基本信息 where" & c & "=" & Combo2.Text
End If
改成
If Adodc1.Recordset.Fields(c).Type = 202 Then
Adodc1.RecordSource = "select * from 基本信息 where " & c & "='" & Combo2.Text & "'"
Else
Adodc1.RecordSource = "select * from 基本信息 where " & c & "=" & Combo2.Text
End If