This example demonstrates using the Refresh method to refresh the Parameters collection for a stored procedure Command object.
Public Sub RefreshX()
Dim cnn1 As ADODB.Connection
Dim cmdByRoyalty As ADODB.Command
Dim rstByRoyalty As ADODB.Recordset
Dim rstAuthors As ADODB.Recordset
Dim intRoyalty As Integer
Dim strAuthorID As String
Dim strCnn As String
' Open connection.
Set cnn1 = New ADODB.Connection
strCnn = "driver={SQL Server};server=srv;" & _
"uid=sa;pwd=;database=pubs"
cnn1.Open strCnn
' Open a command object for a stored procedure
' with one parameter.
Set cmdByRoyalty = New ADODB.Command
cmdByRoyalty.CommandText = "byroyalty"
cmdByRoyalty.CommandType = adCmdStoredProc
cmdByRoyalty.ActiveConnection = cnn1
cmdByRoyalty.Parameters.Refresh
' Get paramater value and execute the command, storing
' the results in a recordset.
intRoyalty = Trim(InputBox( _
"Enter royalty:"))
cmdByRoyalty.Parameters(1) = intRoyalty
Set rstByRoyalty = cmdByRoyalty.Execute
' Open the Authors table to get author names for display.
Set rstAuthors = New ADODB.Recordset
rstAuthors.Open "authors", cnn1
' Print current data in the recordset, adding
' author names from Authors table.
With rstByRoyalty
Debug.Print "Authors with " & intRoyalty & " percent royalty"
Do While Not .EOF
strAuthorID = !au_id
Debug.Print " " & !au_id & ", ";
With rstAuthors
.Filter = "au_id = '" & strAuthorID & "'"
Debug.Print !au_fname & " " & !au_lname
End With
.MoveNext
Loop
.Close
End With
rstAuthors.Close
cnn1.Close
End Sub
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.