使用Resultset数据源填充VB6组合框

时间:2010-11-25 05:57:58

标签: vb6

如何使用结果集数据源填充VB6组合框...请帮助

3 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

我不确定它是否与VB.NET中的工作方式相同,所以我建议您查看ADODB.Recordset对象并将每个项目添加到组合框中。

答案 2 :(得分:0)

将Access数据库中的数据加载到组合框中的一种方法(更改不同数据库的连接字符串):

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