VBScript - Retrieving a Scalar Value From a Stored Procedure on SQL Server 2008
My stored procedure is very simple. It inserts a new record. At the end of it I have the following line:
SELECT SCOPE_IDENTITY()
1) Am I using the right code to return the Primary Key value for the newly inserted record?
2) How do I retrieve this value using ASP Classic/VBScript with ADO Classic开发者_如何学Go?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
The Execute method (NOT Exec) returns a record set which contains the result from the stored procedure.
Set rs = cmdUA.Execute
result = rs.Fields(0).Value
精彩评论