How to P开发者_如何转开发opulate VB6 Combo box using Result set data source ... Please Help
Dim con As New ADODB.Connection
Dim rs2 As New ADODB.Recordset
con.Open "Provider = sqloledb;Data Source=Server01;Initial Catalog=Naveen; User ID= ****; password= ****; Integrated Security= True"
rs2.Open "Select * from Customers", con, adOpenDynamic
Do While rs2.EOF <> True
Combo2.AddItem (rs2.Fields(0).Value)
rs2.MoveNext
Loop
I'm not sure if it works the same way as in VB.NET so I would suggest that you look the ADODB.Recordset object and add each item to the combobox.
One way to load data from an Access database into a combo box (change the connection string for a different DB):
Dim oDb As New ADODB.Connection
Dim oRS As New ADODB.Recordset
Dim sSql As String
oDb.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=C:\Data\MyAccessDB.mdb;Jet"
sSql = "SELECT DISTINCT([LastName]) FROM [Authors] ORDER BY LastName ASC"
oRS.Open sSql, oDB, adOpenForwardOnly, adLockReadOnly
Do While not oRS.EOF
With cboMyCombo
.AddItem trim$(oRS("LastName").Value)
End With
oRS.MoveNext
Loop
oRS.Close
oDB.Close
Set oRS = Nothing
Set oDB = Nothing
精彩评论