ASP从sproc返回OUTPUT值

时间:2011-12-06 06:26:25

标签: tsql stored-procedures asp-classic

如何从sproc返回一个值并将其分配给变量,以便可以在ASP页面上使用?

返回值的存储过程称为sp_Auction_PaymentEwayXMLReceive。 输出变量称为ReturnedMsg

我目前的代码是:

Dim Connection
Dim sSQL, sConnString
sConnString="DRIVER={SQL Server};SERVER=XXXX;UID=XXXX; PWD=XXXX;DATABASE=XXXX;"
    sSQL = "sp_Auction_PaymentEwayXMLReceive '"&eWay.ResultEwayTrxnStatus&"','"&eWay.ResultEwayTrxnNumber&"','"&eWay.ResultEwayTrxnReference&"','"&eWay.ResultEwayTrxnOption1&"','"&eWay.ResultEwayTrxnOption2&"','"&eWay.ResultEwayTrxnOption3&"','"&eWay.ResultEwayAuthCode&"','"&eWay.ResultEwayReturnAmount&"','"&eWay.ResultEwayTrxnError&"' "
    Set sConnection = Server.CreateObject("ADODB.Connection")
    Set connection = Server.CreateObject("ADODB.Connection")
    connection.Open(sConnString)
    connection.execute(sSQL)

- EDIT-- @Andomar

响应1:我也尝试了这个但是我得到了500错误。


            'set up output parameter
            dim outputParameter
            set outputParameter = _
            cmd.CreateParameter("ReturnedMsg",adVarChar, _
            adParamOutput,40)

            'open conn
            connection.Open(sConnString)

            'append OUTPUT  
            cmd.Parameters.Append outputParameter   

            'exec sql   
            connection.execute(sSQL)

-R

1 个答案:

答案 0 :(得分:0)

创建连接后,添加输出参数:

dim outputParameter
set outputParameter = _
    cmd.CreateParameter("OutputParameterName",adVarChar, _
    adParamOutput,40)
cmd.Parameters.Append outputParameter

运行SP后,您可以使用以下值:

Response.Write("<TD>" & _
    cmd.Parameters("OutputParameterName").Value  & "</TD>")