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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With