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

Am I using the Command/Recordset object correctly

Status
Not open for further replies.

BG12424

Programmer
Jun 4, 2002
717
US
Is the way that I am
1) getting the return value,
2) verifying it,
3) then opening a recordset if the return code is successful,
4) returning resultset

the best way to do this? I am concerned with the cmd.Execute and the Set rs = cmd.Execute (calling it twice).


Thanks

function WV_GetQuotePortfolio(userid)
' replace qry_WVGetQuotePortfolio.cfm

dim cmd, rs, 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 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,4)
.Parameters.Append .CreateParameter("@userID",adInteger,adParamInput, ,userid)
.Execute
retval = .Parameters("RETURN_VALUE")
end with

if retval = 1 then
Response.Write("Invalid User")
else
Set rs = Server.CreateObject("ADODB.Recordset")
Set rs = cmd.Execute
do while not rs.EOF
Response.Write(rs(&quot;contract&quot;) & &quot;<br>&quot;)
rs.MoveNext
loop
CloseRS(rs)
end if

CloseCmd(cmd)
CloseDBConn(dbConn)

end function regards,
Brian
 
Why not change your first
Code:
.Execute
code to
Code:
Set rs = Server.CreateObject(&quot;ADODB.Recordset&quot;)
Set rs = cmd.Execute
and remove it from the
Code:
if else then
logic?

Thanks,

Gabe
 
I tried this before and was not able to get the return value back from the stored procedure. From what I have read, You can't get the return value when using the

Set rs = cmd.Execute

The recordset would have to be closed, or the rs.nextrecordset would have to be called in order to access the return value. This was a work-around, but I'm not sure if it has performance impacts.

Thanks,
Brian regards,
Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top