开发者

Populating VB6 Combo box using Resultset data source

开发者 https://www.devze.com 2023-01-26 16:38 出处:网络
How to P开发者_如何转开发opulate VB6 Combo box using Result set data source ... Please HelpDim con As New ADODB.Connection

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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号