Executing Stored Procedures

The execForm method uses the refresh method of the Parameters collection to retrieve the parameter metadata for stored procedures. The following line of code shows the refresh method:

.Parameters.Refresh 

Next, the code loops through the Parameters collection and matches the name of the parameter with the name of the form element, as the following code illustrates. When a match is found, the value of the element is added to the value property of the parameter. When this code is finished running, the Parameters collection contains the name-value pairs that the stored procedure requires. Additional coding handles repeated stored procedure names.

For Each param In .Parameters
   If param.Direction = adParamInput Then
     name = Mid(param.name, 2)
     If oRequest.Form(name).count <= 1 Then
        value = Trim(oRequest.Form(name))
        If value = "" Or value = "null" Then value = Null
        param.value = value

The stored procedure then runs.

Note  The capability to create methods that work for any stored procedure depends on the Parameters collection being refreshed. If the Parameters collection is not refreshed, it has no information about which parameters or parameter types the stored procedure requires. The penalty for this flexibility is that one table action requires two calls to the server, which can hurt application performance.