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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling a store procedure 1

Status
Not open for further replies.
I have the same issue right now; however, my problem deals with traversing the recordset object. I plan on reiterating through the recordset (i.e., movefirst to last and then first to last again). But if you plan on just using the recordset once (first to last) then the syntax is as follows:

'example below contains no input parameters
dim adConn
dim adCmd
dim adRS

set adConn = server.CreateObject("ADODB.Connection")
set adCmd = server.CreateObject("ADODB.Command")
set adRS = server.CreateObject("ADODB.Recordset")

'establish your connection (this is example using sql server)
with adConn
.ConnectionString _ = "Provider=SQLOLEDB;DataSource=ServerName;Initial _
Catalog=DatabaseName;User ID=username;PWD=password"
.Open
end with

'set up the command object information
with adcmd
.CommandText = "storedProcName"
.CommandType = adCmdStoredProc
.ActiveConnection = adConn
end with

'if you are expecting a Recordset to be returned then:
set adRS = adCmd.execute
'or
adRS.Open adCmd

'if you are not expecting a recordset then:
adCmd.execute

If there are parameters then the command object (adCmd) information will change. For example, using the same code above I will include an integer parameter named @id

'set up the command object information
with adcmd
.CommandText = "storedProcName"
.CommandType = adCmdStoredProc
.ActiveConnection = adConn
.Parameters.Append adCmd.CreateParameter( _
("@id",adInteger,adParamInput,,yourValue)
end with

good luck.

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top