VB 中combobox控件链接access数据库的实现代码
想运行时在combobox呈现的是数据库字段“供应商”的列表,代码是怎么写呢,百度来的几种方法都有错误,具体代码要求是什么呀,急啊...
想运行时在combobox呈现的是数据库字段“供应商”的列表,代码是怎么写呢,百度来的几种方法都有错误,具体代码要求是什么呀,急啊
展开
展开全部
Public Sub ShowSheetComboBox(ByRef List1 As ComboBox)
If TableArray = "" Then
getTableArray rem {这是函数}
Else
getTableArray rem {这是函数}
End If
List1.Clear
Dim TblArray As Variant
TblArray = Split(TableArray, ",")
For Each Item In TblArray
List1.AddItem Item
Next
End Sub
{下面括弧内的你要修改}
Public Sub getTableArray()
'd2
DoEvents
Dim cn As adodb.Connection
Set cn = New adodb.Connection
With cn
.ConnectionString = {sConnectionString}
.Open
End With
Dim rs As adodb.Recordset
Set rs = cn.Execute("Select {Colname} from { tablename} ")
TableArray = ""
Do
If Not rs.EOF Then
If TableArray = "" Then
TableArray = TableArray & rs(0).Value
Else
TableArray = TableArray & "," & rs(0).Value
End If
End If
rs.MoveNext
Loop While Not rs.EOF
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
End Sub
If TableArray = "" Then
getTableArray rem {这是函数}
Else
getTableArray rem {这是函数}
End If
List1.Clear
Dim TblArray As Variant
TblArray = Split(TableArray, ",")
For Each Item In TblArray
List1.AddItem Item
Next
End Sub
{下面括弧内的你要修改}
Public Sub getTableArray()
'd2
DoEvents
Dim cn As adodb.Connection
Set cn = New adodb.Connection
With cn
.ConnectionString = {sConnectionString}
.Open
End With
Dim rs As adodb.Recordset
Set rs = cn.Execute("Select {Colname} from { tablename} ")
TableArray = ""
Do
If Not rs.EOF Then
If TableArray = "" Then
TableArray = TableArray & rs(0).Value
Else
TableArray = TableArray & "," & rs(0).Value
End If
End If
rs.MoveNext
Loop While Not rs.EOF
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询