2

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

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

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
4

1 回答 1

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
于 2013-03-21T16:07:24.567 回答