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("RETURN_VALUE"
end with
if retval = 1 then
Response.Write(cstr(retval))
else
do while not rs.eof
Response.Write(rs("contract"
& "<BR>"
rs.movenext
loop
end if
CloseRS(rs)
CloseDBConn(dbConn)
end function
-----------------------------
GOOD 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 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)
.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("RETURN_VALUE"
end with
if retval = 1 then
Response.Write("Invalid User"
end if
CloseDBConn(dbConn)
end function
regards,
Brian
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("RETURN_VALUE"
end with
if retval = 1 then
Response.Write(cstr(retval))
else
do while not rs.eof
Response.Write(rs("contract"
rs.movenext
loop
end if
CloseRS(rs)
CloseDBConn(dbConn)
end function
-----------------------------
GOOD 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 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)
.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("RETURN_VALUE"
end with
if retval = 1 then
Response.Write("Invalid User"
end if
CloseDBConn(dbConn)
end function
regards,
Brian