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 还望大家帮忙 小女子在这谢谢了 展开
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 还望大家帮忙 小女子在这谢谢了 展开
1个回答
展开全部
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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询