Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing Stored Procedure from ADO Control

Status
Not open for further replies.

AOLBoy

IS-IT--Management
May 7, 2002
68
GB
I have used an ADO control to retrieve data via a stored procedure in my SQL Server database.

The stored procedure requires a single parameter (char string), but I can't seem to find the syntax for passing the parameter. Any help would be much appreciated.
 
Hi there,

you have to create a command object with a stored procedure command type, then create a parameter object for each parameter you have and add it to you parameters collection of your command object. Then associate the value to the parameter to the command object and execute the command object. In code it looks something like:

Code:
dim prm as ADODB.Parameter
dim cmd as ADODB.command

Set cmd = New ADODB.Command
With cmd
  Set .ActiveConnection = myConnectionObject
      .CommandType = adCmdStoredProc
      .CommandText = myProcedureName
      
  Set prm = .CreateParameter("myParam", adVarChar, adParamInput, 12)
  .Parameters.Append prm
  
  .Parameters("myParam").Value = ParamExample1
  .Execute
end With

Hope this helps,

Nath
 
Thanks for that Nath, but my problem is within the ADO control. On the Record Source tab of the Prperty Pages I have set the command type to 4 - adCmdStoredProc. In the Table or Stored Procedure Name I need to enter the Stored Procedure name along with the parameter value, such as

SP 'A1'

where SP is the Stored Procedure name and 'A1' is the parameter.

Any ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top