VBScript - 从 SQL Server 2008 上的存储过程检索标量值

HK1*_*HK1 4 sql-server vbscript ado asp-classic

我的存储过程非常简单。它插入一条新记录。最后我有以下行:

SELECT SCOPE_IDENTITY()
Run Code Online (Sandbox Code Playgroud)

1)我是否使用正确的代码返回新插入记录的主键值?
2) 如何使用 ASP Classic/VBScript 和 ADO Classic 检索该值?

Dim cmdUA
Set cmdUA = Server.CreateObject("ADODB.Command")
Set cmdUA.ActiveConnection = tcon
cmdUA.CommandText = "InsertUserAgent"
cmdUA.CommandType = adCmdStoredProc 
cmdUA.Parameters.Append cmdUA.CreateParameter("useragent", adVarWChar, _
adParamInput, 1000)
cmdUA("useragent") = Request.ServerVariables("HTTP_USER_AGENT")
cmdUA.Exec
'Here I need to get the value returned from the stored procedure
Set cmdUA.ActiveConnection = Nothing
Set cmdUA = Nothing
Run Code Online (Sandbox Code Playgroud)

Ric*_*der 5

Execute 方法(NOT Exec)返回一个记录集,其中包含存储过程的结果。

 Set rs = cmdUA.Execute
 result = rs.Fields(0).Value
Run Code Online (Sandbox Code Playgroud)