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!

calling stored procedures?

Status
Not open for further replies.

sankur

Programmer
Jul 10, 2002
8
can i get a code for calling stored procedures from sql server. a stored procecdure like insert?
 
1) Stored procedures, no input, no output:
YourConnection.Execute "EXEC YourStoredProc"

2) Stored procedures, return recordset, input variables:
YourRecordset.Open "EXEC YourStoredProc '" & YourStringVar & "'," & Cstr(YourNumericVar),YourConnection

3) Stored procedures with output parameters:
----------------------------------------
With YourCommand
.ActiveConnection = YourConnection
.CommandText = "YourStoredProc"
.CommandType = AdCmdStoredProc
.Parameters.Append .CreateParameter("@ServerVarCharIn", adVarChar, adParamInput, 255)
p.Append .CreateParameter("@ServerIntegerIn, adInteger, adParamOutput)
p.Append .CreateParameter("@ServerIntegerOut", adInteger, adParamOutput)
End With
'The code below can be repeated any number of times
YourCommand("@ServerVarCharIn") = "Hello"
YourCommand("@ServerIntegerIn") = 42
YourCommand.Execute
Msgbox "The Stored Procedure returned " & Cstr(YourCommand("@ServerIntegerOut"))
----------------------------------------

Even though it can be tempting to return values in a recordset(because of the much shorter syntax), it is much faster to return values in output parameters with the Command Object. So, if you are only returning a few values: use the Command Object.
Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top