-
How to pass return value to ASP from a stored procedure
I am trying to return value from a stored procedure to ASP.
But I always got the error msg said "ADODB.Command error '800a0bb9' The application is using arguments that are of the wrong type, are out of acceptable range, or are in conflict with one another."
Here is my code in ASP to call the stored proc.
<%
Set objConnection = Server.CreateObject("ADODB.Connection" ConnString = "DSN=;UID=;PWD=;"
objConnection.Open ConnString
Set cmd = Server.CreateObject("ADODB.Command"
Set cmd.ActiveConnection = objConnection
cmd.CommandText = "{call sp_test(?,?,?,?,?,?)}"
cmd.Parameters.Append cmd.CreateParameter("RetVal", adInteger, adParamOutput)
cmd.Parameters.Append cmd.CreateParameter("tranType", adVarChar, adParamInput)
cmd.Parameters.Append cmd.CreateParameter("debitAcct", adVarChar, adParamInput)
cmd.Parameters.Append cmd.CreateParameter("creditAcct", adVarChar, adParamInput)
cmd.Parameters.Append cmd.CreateParameter("amount", adVarChar, adParamInput)
cmd.Parameters.Append cmd.CreateParameter("reference", adVarChar, adParamInput)
cmd.Parameters("tranType" = TransactionType
cmd.parameters("debitAcct" = DebitAcct
cmd.parameters("creditAcct" = CreditAcct
cmd.parameters("amount" = Amount
cmd.parameters("reference" = Reference
cmd.Execute
Response.write cmd.parameters("RetVal"
%>
and in the stored proc, I declared @RetVal as the output parameter, and assigned it to a variable @REstatus, since I used this variable several times within this stored proc.
create procdeure sp_test
(
@ReVal int output,
@tranType varchar(3),
@debitAcct varchar(8),
@creditAcct varchar(8),
@amount varchar(32),
@reference varchar(80)
)
As
begin
declare @REstatus int,
select @RetVal = @REstatus
------------
begin transaction
update table_name
--------------
if @@error <> 0
rollback transaction
select @REstatus = -1
return -1
else
commit transaction
select @REstatus = 0
return 0
end
go
I guess there must be some problems with my stored procedure, since when I execute it inside SQL server, I used:
exec sp_test @ReVal=@REstatus output,
@tranType='-',@debitAcct='-',@creditAcct='-',@amount='-',@reference='-'
then returned me wrong msg: you must declare variable @REstatus, but I declared it in the procedure.
Could someone help me out of this? Thanks in advance.
zhe
-
How to pass return value to ASP from a stored procedure (reply)
Hi Zhe,
Try posting this question on the ASP support forum. Here we help solve problems with the ASP-db product which does all that work you're referring to for you. Check out www.aspdb.com for more info.
Thanks,
John
------------
zhe song at 7/27/99 1:40:17 PM
I am trying to return value from a stored procedure to ASP.
But I always got the error msg said "ADODB.Command error '800a0bb9' The application is using arguments that are of the wrong type, are out of acceptable range, or are in conflict with one another."
Here is my code in ASP to call the stored proc.
<%
Set objConnection = Server.CreateObject("ADODB.Connection" ConnString = "DSN=;UID=;PWD=;"
objConnection.Open ConnString
Set cmd = Server.CreateObject("ADODB.Command"
Set cmd.ActiveConnection = objConnection
cmd.CommandText = "{call sp_test(?,?,?,?,?,?)}"
cmd.Parameters.Append cmd.CreateParameter("RetVal", adInteger, adParamOutput)
cmd.Parameters.Append cmd.CreateParameter("tranType", adVarChar, adParamInput)
cmd.Parameters.Append cmd.CreateParameter("debitAcct", adVarChar, adParamInput)
cmd.Parameters.Append cmd.CreateParameter("creditAcct", adVarChar, adParamInput)
cmd.Parameters.Append cmd.CreateParameter("amount", adVarChar, adParamInput)
cmd.Parameters.Append cmd.CreateParameter("reference", adVarChar, adParamInput)
cmd.Parameters("tranType" = TransactionType
cmd.parameters("debitAcct" = DebitAcct
cmd.parameters("creditAcct" = CreditAcct
cmd.parameters("amount" = Amount
cmd.parameters("reference" = Reference
cmd.Execute
Response.write cmd.parameters("RetVal"
%>
and in the stored proc, I declared @RetVal as the output parameter, and assigned it to a variable @REstatus, since I used this variable several times within this stored proc.
create procdeure sp_test
(
@ReVal int output,
@tranType varchar(3),
@debitAcct varchar(8),
@creditAcct varchar(8),
@amount varchar(32),
@reference varchar(80)
)
As
begin
declare @REstatus int,
select @RetVal = @REstatus
------------
begin transaction
update table_name
--------------
if @@error <> 0
rollback transaction
select @REstatus = -1
return -1
else
commit transaction
select @REstatus = 0
return 0
end
go
I guess there must be some problems with my stored procedure, since when I execute it inside SQL server, I used:
exec sp_test @ReVal=@REstatus output,
@tranType='-',@debitAcct='-',@creditAcct='-',@amount='-',@reference='-'
then returned me wrong msg: you must declare variable @REstatus, but I declared it in the procedure.
Could someone help me out of this? Thanks in advance.
zhe
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|