ASP获取存储过程Return返回值和Output输出

1,ASP获取存储过程获取Return返回值
存储过程代码

--存储过程
Create PROCEDURE MYSQL
    @a int,
    @b int
AS
    return @a + @b
GO

asp代码

Set conn = Server.CreateObject("ADODB.Connection")
conn.open "Driver={SQL Server};server=192.168.1.69;uid=sa;pwd=sa;database=union_5k3g;"
Set MyCommand = Server.CreateObject("ADODB.Command")
MyCommand.Parameters.append MyCommand.CreateParameter("@return",3,4)
MyCommand.Parameters.append MyCommand.CreateParameter("@a",3,1,50,10)
MyCommand.Parameters.append MyCommand.CreateParameter("@b",3,1,50,20)
MyCommand.CommandType = 4
MyCommand.ActiveConnection = conn
MyCommand.CommandText = "MYSQL"
MyCommand.execute
Response.Write(MyCommand.Parameters("@return"))
Set MyCommand = Nothing
conn.close
Set conn = Nothing

  注:获取Return返回值的@return一项必须放在@a和@b之前,否则会出错提示"[Microsoft][ODBC SQL Server Driver][SQL Server]为过程或函数 MYSQL 指定的参数太多"!!!

2,ASP获取存储过程获取Output输出参数值
存储过程

Create PROCEDURE MYSQL
   @a int,
   @b int,
    @c int output
AS
    Set @c = @a + @b
GO
Set conn = Server.CreateObject("ADODB.Connection")
conn.open "Driver={SQL Server};server=192.168.1.69;uid=sa;pwd=sa;database=union_5k3g;"
Set MyCommand = Server.CreateObject("ADODB.Command")
MyCommand.Parameters.append MyCommand.CreateParameter("@a",3,1,50,20)
MyCommand.Parameters.append MyCommand.CreateParameter("@b",3,1,50,20)
MyCommand.Parameters.append MyCommand.CreateParameter("@c",3,2,50)
MyCommand.CommandType = 4
MyCommand.ActiveConnection = conn
MyCommand.CommandText = "MYSQL"
MyCommand.execute
Response.Write(MyCommand.Parameters("@c"))
Set MyCommand = Nothing
conn.close
Set conn = Nothing

关于CreateParameter参数解释,可以参考Asp CreateParameter参数详解

加支付宝好友偷能量挖...


评论(0)网络
阅读(41)喜欢(0)Asp/VBScript