Vb6 从sql表填充组合框时出现问题

Vb6 从sql表填充组合框时出现问题,vb6,Vb6,需要一些小的帮助。我遇到了一个问题,因为我的组合框不会填充我正在引用的表。这是我的密码: Public Function GetCodeDesc(sCode As String) As String Dim strSQL As String, strAnswer As String Dim objGetInfo As New ADODB.Recordset strSQL = "SET ANSI_NULLS OFF" Set objGetInfo = New AD

需要一些小的帮助。我遇到了一个问题,因为我的组合框不会填充我正在引用的表。这是我的密码:

Public Function GetCodeDesc(sCode As String) As String
    Dim strSQL As String, strAnswer As String
    Dim objGetInfo As New ADODB.Recordset

    strSQL = "SET ANSI_NULLS OFF"
    Set objGetInfo = New ADODB.Recordset
    objGetInfo.Open strSQL, objConnection, adOpenForwardOnly, adLockOptimistic

    strSQL = "SELECT DISTINCT * FROM SH_RAWOCODES WHERE CODEX='" & sCode   & "'       ORDER BY CODEX"
    Set objGetInfo = New ADODB.Recordset
    objGetInfo.Open strSQL, objConnection, adOpenForwardOnly, adLockOptimistic

    If Not objGetInfo.EOF And Not objGetInfo.BOF Then
        strAnswer = objGetInfo.Fields(28)
    End If

    strSQL = "SET ANSI_NULLS ON"
    Set objGetInfo = New ADODB.Recordset
    objGetInfo.Open strSQL, objConnection, adOpenForwardOnly, adLockOptimistic

    GetCodeDesc = strAnswer
End Function


谁能告诉我哪里出了问题

您没有显示任何将项目添加到组合框的代码,所以我猜您没有。在您的示例中,我也没有看到您希望返回的记录超过1条,因此我将提供一个通用的组合框例程

If objGetInfo.EOF = False And objGetInfo.BOF = False Then
    objGetInfo.MoveFirst 'redundant, but just to be sure we're on the first record
    Combobox1.Clear 'clear any current items
    Do While objGetInfo.EOF = False
        Combobox1.AddItem objGetInfo.Fields("MyField").Value
        objGetInfo.MoveNext 'move to the next record
    Loop
End If

了解问题所在会有所帮助。您的问题似乎正在从查询中返回结果,与将其放入组合框无关。好的,问题是我需要组合框来显示提供的表的内容,由于某些原因,我缺少一些不会显示我分配给显示的表的内容的内容。非常感谢jac!!