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!

Question about return values

Status
Not open for further replies.

BG12424

Programmer
Jun 4, 2002
717
US
I need to be able to check return codes and act appropriately based on their values, but am having difficulties doing this. Please see the 2 pieces of code below.

BAD CODE: Code that executes a stored procedure using the command object and stores results in a recordset object. I am unable to get the return code using this method.

GOOD CODE: Code that executes a stored procedure using the command object. I am able to get the return code from the stored procedure, but I am unable to navigate through the recordset that is returned.

PLEASE HELP......
-----------------------------
BAD CODE
-----------------------------
function WV_GetQuotePortfolio(userid)

dim cmd, dbConn, retval

strConn = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=flibble;Initial Catalog=WV_DEV;Network Address=GAINES-XE3-W2K"
Set rs = Server.CreateObject("ADODB.Recordset")
Set dbConn = Server.CreateObject("ADODB.Connection")
dbConn.Open strConn

Set cmd = Server.CreateObject("ADODB.Command")
with cmd
.ActiveConnection = dbConn
.CommandText = "WVGetQuotePortfolio"
.CommandType = adCmdStoredProc
.Parameters.Append .CreateParameter("RETURN_VALUE", adInteger,adParamReturnValue)
.Parameters.Append .CreateParameter("@userID",adInteger,adParamInput, ,userid)
Set rs = .Execute <---------- CANNOT DO THIS AND GET RETURN CODE VALUE
retval = .Parameters(&quot;RETURN_VALUE&quot;)
end with

if retval = 1 then
Response.Write(cstr(retval))
else
do while not rs.eof
Response.Write(rs(&quot;contract&quot;) & &quot;<BR>&quot;)
rs.movenext
loop
end if

CloseRS(rs)
CloseDBConn(dbConn)

end function


-----------------------------
GOOD CODE
-----------------------------
function WV_GetQuotePortfolio(userid)

dim cmd, dbConn, retval

strConn = &quot;Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=flibble;Initial Catalog=WV_DEV;Network Address=GAINES-XE3-W2K&quot;
Set dbConn = Server.CreateObject(&quot;ADODB.Connection&quot;)
dbConn.Open strConn

Set cmd = Server.CreateObject(&quot;ADODB.Command&quot;)
with cmd
.ActiveConnection = dbConn
.CommandText = &quot;WVGetQuotePortfolio&quot;
.CommandType = adCmdStoredProc
.Parameters.Append .CreateParameter(&quot;RETURN_VALUE&quot;, adInteger,adParamReturnValue)
.Parameters.Append .CreateParameter(&quot;@userID&quot;,adInteger,adParamInput, ,userid)
.Execute <---- THIS GIVES ME A RETURN CODE VALUE, BUT HOW DO I GET THE DATA RESULTS INTO A RECORDSET OBJECT IF THERE IS RESULTING DATA?????
retval = .Parameters(&quot;RETURN_VALUE&quot;)
end with

if retval = 1 then
Response.Write(&quot;Invalid User&quot;)
end if

CloseDBConn(dbConn)

end function

regards,
Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top