使用vb6中的存储过程填充组合框

时间:2013-03-21 14:54:50

标签: mysql database stored-procedures vb6 combobox

如何使用存储过程在运行时填充组合框以从数据库中获取值?

这是我的代码,这应该转换为存储过程:

Private Sub ComboFill()
Set Rs = New ADODB.Recordset
Set Cmd = New ADODB.Command
With Cmd
.ActiveConnection = Conn
.CommandType = adCmdText
.CommandText = "SELECT suppliername from supplier"
 Set Rs = .Execute
End With

If Not (Rs.BOF And Rs.EOF) Then
Rs.MoveFirst
End If

Do Until Rs.EOF
txtsupplier.AddItem Rs.Fields("suppliername").Value
Rs.MoveNext
Loop
End Sub

1 个答案:

答案 0 :(得分:2)

试试这个(未经测试):

编辑:已调整为返回RS,而不是单个值

Set Rs = New ADODB.Recordset
Set cn = New ADODB.Connection
cn.ConnectionString = Session.GetConnectionstring
cn.Open

Set cmd = New ADODB.Command
cmd.ActiveConnection = cn
cmd.CommandType = adCmdStoredProc
cmd.CommandText = “MyStoredProcdure”
' Input param, if you need
' cmd.Parameters.Append cmd.CreateParameter(“Param1”, adInteger, adParamInput, , 614)
' Create a recordset by executing the command.
Set Rs = cmd.Execute()
Rs.MoveFirst()

Do Until Rs.EOF
    txtsupplier.AddItem Rs.Fields("suppliername").Value
Rs.MoveNext

Set Rs = Nothing
Set cmd = Nothing
Set cn = Nothing