如何让combobox显示数据库中的所有字段?
1个回答
展开全部
Private Sub Form_Load()
Dim cn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim SqlStr As String
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb;Mode=ReadWrite;Persist Security Info=False;Jet OLEDB:Database Password=123"
SqlStr = "Select 会员姓名 From 会员消费"
rst.CursorLocation = adUseClient
rst.Open SqlStr, cn, adOpenDynamic, adLockOptimistic, adCmdText '打开记录集
Combo1.Text = rst.Fields("会员姓名").Value
Do While rst.EOF = False
Combo1.AddItem rst.Fields("会员姓名").Value
rst.MoveNext
Loop
End Sub
Dim cn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim SqlStr As String
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb;Mode=ReadWrite;Persist Security Info=False;Jet OLEDB:Database Password=123"
SqlStr = "Select 会员姓名 From 会员消费"
rst.CursorLocation = adUseClient
rst.Open SqlStr, cn, adOpenDynamic, adLockOptimistic, adCmdText '打开记录集
Combo1.Text = rst.Fields("会员姓名").Value
Do While rst.EOF = False
Combo1.AddItem rst.Fields("会员姓名").Value
rst.MoveNext
Loop
End Sub
追问
combobox的datasource和datafield设置好后,接下来做什么?
追答
不要设置,要用代码控制,自由、灵活,便于复制再用
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询