vb Combo控件与数据库

数据库(请看图片):http://p15.freep.cn/p.aspx?u=v20_p15_p_0806062243504338_0.jpgCombo1和Combo2C... 数据库(请看图片):
http://p15.freep.cn/p.aspx?u=v20_p15_p_0806062243504338_0.jpg

Combo1 和 Combo2

Combo1 读取 字段1 “移动”“网通”(不可重复)

Combo2 根据字段1 读取字段2 “销售”“领导”(不可重复)

Combo2 选择 “销售”或“领导”

ListView1 显示所有结果

例如:选择--移动--领导

则ListView1显示:
李三
李四

============================

谢谢
QQ 8588051 还望大家帮忙 小女子在这谢谢了
展开
 我来答
lzh741206
2008-06-06 · TA获得超过1192个赞
知道大有可为答主
回答量:1929
采纳率:100%
帮助的人:2793万
展开全部
Public Function OpenConnForAccess(ByVal FileName As String) As ADODB.Connection
Dim AdoConn As New ADODB.Connection
With AdoConn
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FileName & ";Persist Security Info=False"
.Open
End With
Set OpenConnForAccess = AdoConn
End Function

Public Function OpenRecordset(ByVal strSql As String, ByVal AdoConn As ADODB.Connection) As ADODB.Recordset
Dim rs As New ADODB.Recordset
With rs
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.Open strSql, AdoConn, , , adCmdText
End With
Set OpenRecordset = rs
End Function

Private Sub Form_Load()
Dim conn As ADODB.Connection
Set conn = OpenConnForAccess(App.Path & "\test1.mdb")
Dim rs As ADODB.Recordset
Set rs = OpenRecordset("select distinct 公司 from test", conn)
Do While Not rs.EOF
Combo1.AddItem rs(0)
rs.MoveNext
Loop
End Sub
Private Sub Combo1_Click()
Dim conn As ADODB.Connection
Set conn = OpenConnForAccess(App.Path & "\test1.mdb")
Dim rs As ADODB.Recordset
Set rs = OpenRecordset("select distinct 部门 from test where 公司 = '" & Combo1.Text & "'", conn)
Combo2.Clear
Do While Not rs.EOF
Combo2.AddItem rs(0)
rs.MoveNext
Loop
End Sub

Private Sub Combo2_Click()
Dim conn As ADODB.Connection
Set conn = OpenConnForAccess(App.Path & "\test1.mdb")
Dim rs As ADODB.Recordset
Set rs = OpenRecordset("select 人员 from test where 公司 = '" & Combo1.Text & "' and 部门 = '" & Combo2.Text & "'", conn)
ListView1.ListItems.Clear
Do While Not rs.EOF
ListView1.ListItems.Add , , rs(0)
rs.MoveNext
Loop
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式