我通过vbs执行了一个SQL存储过程,存储过程有一个返回值,我如何通过vbs获取这个返回值啊?
经监控,vbs已经成执行了存储过程,但不知道如何获得sp的返回值!
我的脚本如下:
Call dbConnection.Open (strCnn)
Dim strSql
strSql = "Declare @iCount int; "
strSql = strSql & "Exec testSP @iCount output, 'sp2'; "
strSql = strSql & "Select @iCount "
Call dbConnection.Execute (strSql)
sp返回值在变量@iCount中
dim conn
set conn=WScript.CreateObject("ADODB.Connection")
conn.Open "Driver={SQL server};server=服务器;database=数据库;uid=账号;pwd=密码;"
dim rst
set rst=WScript.CreateObject("ADODB.Recordset")
sSQL="declare @B int exec sp_test 2,@B output select @B"
rst.open sSQL,conn,1,1
WScript.Echo rst(0)
WScript.QUIT
rst.close
set rst=nothing
conn.close
set conn=nothing
把你上面的代码拼成存储过程,结尾加returns @iCount
然后 int rv=dbConnection.Execute(strSql) 搞定