VB中combobox链接ACCESS数据库代码怎么写(带注释)。

VB中combobox链接ACCESS数据库代码怎么写(带注释)。,第1张

先查数据库,用ADO控件也好用ODBC也好或者DAO都会有和数据集合。

While Not rs.EOF

Combo1.SelectItem.Add rs.Fields("字段名")

rs.MoveNext

Wend

Public Sub ShowSheetComboBox(ByRef List1 As ComboBox)

If TableArray = "" Then

getTableArrayrem {这是函数}

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


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/7903066.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-11
下一篇 2023-04-11

发表评论

登录后才能评论

评论列表(0条)

保存