vb adodc 控件的问题
界面有两个COMBO控件,combo1是存放字段名称的,combo2存放字段值代码如下:PrivateSubForm_Load()'载入时把字段名添加到combo1中Ad...
界面有两个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
Adodc1.RecordSource = "select * from 基本信息 where" & c & "=" & Combo2.Text
End If
Adodc1.Refresh '就是这里出现错误了,删除后没事
End Sub
怎么搞的呢 展开
代码如下:
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
Adodc1.RecordSource = "select * from 基本信息 where" & c & "=" & Combo2.Text
End If
Adodc1.Refresh '就是这里出现错误了,删除后没事
End Sub
怎么搞的呢 展开
2个回答
展开全部
你的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
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
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询