Handy Manny
Handy Manny

Reputation: 388

Fill up combobox using stored procedure in vb6

How to fill up combobox during runtime using stored procedure to get values from database?

here's my code, this should be converted into stored procedure:

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

Upvotes: 2

Views: 2191

Answers (1)

George
George

Reputation: 2213

Try this (not tested):

EDIT: adjusted to return a RS, not a single value

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

Upvotes: 2

Related Questions