Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server VBScript-从SQL Server 2008上的存储过程中检索标量值_Sql Server_Vbscript_Asp Classic_Ado - Fatal编程技术网

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

Sql server VBScript-从SQL Server 2008上的存储过程中检索标量值,sql-server,vbscript,asp-classic,ado,Sql Server,Vbscript,Asp Classic,Ado,我的存储过程非常简单。它插入一条新记录。最后我有以下几行: SELECT SCOPE_IDENTITY() 1) 我是否使用正确的代码为新插入的记录返回主键值? 2) 如何使用ASP Classic/VBScript和ADO Classic检索此值 Dim cmdUA Set cmdUA = Server.CreateObject("ADODB.Command") Set cmdUA.ActiveConnection = tcon cmdUA.CommandText = "InsertUser

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

SELECT SCOPE_IDENTITY()
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
Execute方法(非Exec)返回一个记录集,其中包含存储过程的结果

 Set rs = cmdUA.Execute
 result = rs.Fields(0).Value
我不得不使用rs(0)而不是rs.Fields(0).Value,但我不知道为什么。此外,对于任何稍后可能查看此答案的新手来说,“rs”是一个记录集变量,“result”也是一个变量,两者都未在此处声明。