如何从SQL记录集中填充VB6中的ComboBox?

时间:2016-09-28 19:45:33

标签: sql-server combobox vb6

我正在尝试使用从SQL中提取的RecordSet在VB6中填充ComboBox。我在SQL中编写了一个存储过程,它返回一个如下所示的RecordSet:

记录集:

enter image description here

我在VB6中编写了一个函数,将RecordSet分配给变量:rsRetData。在我的用户表单上,我有一个名为cboxRejectReasons的ComboBox。我希望从下拉列表中列出RecordSet中的所有Descriptions,并且关联的SelectCode仍然附加到Description

这是存储过程代码(抱歉由于某种原因格式化了):

    ALTER PROCEDURE [dbo].[uspTheoLossGetRejectCodes]
    -- Add the parameters for the stored procedure here

AS
BEGIN
    SET NOCOUNT ON;

    -- Insert statements for procedure here
    SELECT SelectCode, Description, MeltLineEnabled
    FROM   tblSelectCodes
    WHERE  (LanguageID = 1) AND (SelectCode >= 100) AND (MeltLineEnabled = 1) 
    ORDER BY Description

    SET NOCOUNT OFF;
END

这是VB6函数,它将RecordSet分配给变量rsRetData:

Public Function TheoLossCalcRejectError()
Dim lErrorCode          As EBOD_ComponentErrorCodes
Dim sErrorDescription   As String
Dim objStoredProc       As StoredProcedure.IStoredProcedure


Set objStoredProc = CreateObject("StoredProcedure.IStoredProcedure")
With objStoredProc
    .NewStoredProcedure

    If .Open_Connection(lErrorCode, sErrorDescription) Then
    Set rsRetData = .ExecuteReturnRecordset(USPPARNAME_GETREJECTCODES, lErrorCode, sErrorDescription)
    End If
    .Close_Connection
End With
Set objStoredProc = Nothing

End Function

该函数正确执行并正确分配了RecordSet。

我怎样才能实现这一目标?

0 个答案:

没有答案