0

我无法找到完全涵盖这一点的问题/答案,因此我问这个问题。我需要做的是运行一个带有 1 个参数的存储过程。它将返回一组我需要存储在记录集中的结果。我计划稍后循环遍历这个记录集。对于较旧的 asp,我非常缺乏经验,但这是我必须要做的:

dim myConn
Set myConn = Server.CreateObject("ADODB.Connection")
myConn.Open = ("DSN=example-dsn;SERVER=example-server;DATABASE=example-db;UID=user;PWD=pass;")

dim oStoredProc : Set oStoredProc = Server.CreateObject("ADODB.Command")
With oStoredProc
    .ActiveConnection = myConn
    .CommandType = adCmdStoredProc
    .CommandText = "myStoredProcedure"
    .Parameters.Append(.CreateParameter("@PARAM1", ADODB.adInteger, ADODB.adParamInput, 10, 2012))
    Dim rs : Set rs = .Execute() 

End With

// Will loop through it here.

我的猜测是我没有正确设置记录集,但就像我说的那样,我不太确定。如果有人能指出我正确的方向,我将不胜感激!

4

3 回答 3

1

您需要确保您的结果集是正确的对象

set rs = Server.CreateObject("ADODB.Recordset")

然后您将使用我认为它的open 方法,它的工作原理如下:

   rs.Open oStoredProc

然后使用Record Set 对象的其他成员循环遍历结果。

于 2012-06-01T22:01:08.623 回答
1

好吧,我做错了几件事,但最终对我有用。首先,事实证明我不需要传入参数,但这无论如何都不是问题。主要问题之一是“adCmdStoredProc”未被识别,这很奇怪,因为我已经看到它在其他任何地方都使用过,但是用它的相应值 4 替换它确实有效。

dim myConn, cmd

Set myConn = Server.CreateObject("ADODB.Connection")
myConn.Open = ("DSN=[BLAH];SERVER=[SERVER];DATABASE=[BLAH];UID=[User];PWD=[Pass];")

dim oStoredProc : Set oStoredProc = Server.CreateObject("ADODB.Command")
oStoredProc.CommandType = 4 
oStoredProc.CommandText = "StoredProcedureName"
oStoredProc.ActiveConnection = myConn
// Add parameters here if needed.

Dim rs 
Set rs = oStoredProc.Execute()

// I Loop through here

rs.Close
myConn.Close
Set rs = Nothing
Set oStoredProc = Nothing
Set myConn = Nothing

如果其他人需要,我希望这会有所帮助。

于 2012-06-04T17:28:49.873 回答
-1
Dim rsStk As New ADODB.Recordset

Set rsStk = cnnPck.Execute("SP_JOB_ALL '" & Trim(te_Item) & "'")

Set Recordset= CONNECTION .Execute()

这是做这件事的简单方法

于 2014-04-30T07:35:46.820 回答