VBScript - 从 SQL Server 2008 上的存储过程检索标量值
我的存储过程非常简单。它插入一条新记录。在它的末尾,我有以下行:
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Execute 方法(NOT Exec)返回一个记录集,其中包含存储过程的结果。
The Execute method (NOT Exec) returns a record set which contains the result from the stored procedure.