如何在asp经典中调用存储过程?

时间:2013-05-13 14:04:32

标签: sql-server stored-procedures asp-classic

在我的asp代码中,我想调用一个存储过程。这是我正在使用的代码:

newHireSQL = "EXEC sp_selectNewHireSQL"
Set rsGetHireID = Server.CreateObject("ADODB.Recordset")
rsGetHireID.Open newHireSQL,ConnectionString,adOpenStatic

但是我不想这样写。我想使用这段代码:

Dim Conn
SET rsGetHireID = Server.CreateObject("ADODB.RecordSet")
SET Conn = Server.CreateObject("ADODB.Command")
Conn.CommandText = "sp_selectNewHireSQL"
Conn.CommandType = adCmdStoredProc
Conn.ActiveConnection = ConnectionString
Set rsGetHireID = Conn.Execute

但是对于这段代码,我得到的记录集的记录数为-1

有谁知道为什么会发生这种情况以及如何解决这个问题?

感谢。

1 个答案:

答案 0 :(得分:0)

修复-1问题给出正确的光标:

SET rsGetHireID = Server.CreateObject("ADODB.RecordSet")
SET oCommand = Server.CreateObject("ADODB.Command")
oCommand.CommandText = "sp_selectNewHireSQL"
oCommand.CommandType = adCmdStoredProc
oCommand.ActiveConnection = ConnectionString
rsGetHireID.CursorLocation = 3 'adUseClient
rsGetHireID.Open oCommand