请问在VB中ComboBox如何绑定数据库,绑定后是显示字段的全部记录,而不是第一个记录
2个回答
展开全部
Private Sub Form_Load()
Dim con As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim sql As String
Dim conn As String
con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=database.mdb;Persist Security Info=False"
sql = "select user from users"
rst.Open sql, con, adOpenKeyset, adLockOptimistic
Combo1.Clear
Do While Not rst.EOF
Combo1.AddItem (Trim(rst(0)))
rst.MoveNext
Loop
rst.Close
con.Close
End Sub
Dim con As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim sql As String
Dim conn As String
con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=database.mdb;Persist Security Info=False"
sql = "select user from users"
rst.Open sql, con, adOpenKeyset, adLockOptimistic
Combo1.Clear
Do While Not rst.EOF
Combo1.AddItem (Trim(rst(0)))
rst.MoveNext
Loop
rst.Close
con.Close
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询