我正在使用带有3个参数的Classic ASP处理SQL Server存储过程。我试图找到记录数,但它返回'-1'。
我看到了类似的post,做了建议的事情(检查游标类型,并在存储过程中添加'set nocount on'),但是这些更改并未影响-1记录计数。
这是我在下面的经典ASP页面中的代码。
strInterestName = request("InterestName")
strActiveDate = request("activedate")
strExpireDate = request("expiredate")
Set objCommandSec = CreateObject("ADODB.Command")
Set objRS = CreateObject("ADODB.RecordSet")
objRS.cursorlocation = 3
objRS.cursortype = adOpenStatic
With objCommandSec
Set .ActiveConnection = objConnection
.CommandText = "[01_cms_search_pg_select_news_items_4]"
.CommandType = 4
.Parameters.Append .CreateParameter("@InterestName",adVarChar,
adParamInput, 25)
.Parameters.Append .CreateParameter("@ActiveDate",adDate, adParamInput)
.Parameters.Append .CreateParameter("@ExpireDate",adDate,
adParamInput)
.Parameters("@InterestName") = strInterestName
.Parameters("@ActiveDate") = strActiveDate
.Parameters("@ExpireDate") = strExpireDate
set objRS =.Execute()
End With
这是存储过程的代码,如下:
ALTER PROCEDURE [dbo].[01_cms_search_pg_select_news_items_4]
@InterestName varchar(50),
@ActiveDate datetime,
@ExpireDate datetime
AS DECLARE @sql nvarchar(4000)
SELECT @sql = ' SELECT * ' +
' FROM news ' +
' WHERE ' +
' bulletin_display_indicator = ''true'' '+
' AND ' +
' website_homepg_display_indicator= ''false'' '
IF @InterestName is not null
SELECT @sql = @sql + ' AND (InterestName = @InterestName)
IF @ExpireDate is not null and @ExpireDate IS NOT NULL
SELECT @sql = @sql + ' AND (expiredate between @ActiveDate and @ExpireDate)
SELECT @sql = @sql + '; '
EXEC sp_executesql @sql, N'@InterestName varchar(50), @ActiveDate
DateTime, @ExpireDate DateTime',@InterestName, @ActiveDate,
@ExpireDate
答案 0 :(得分:1)
我为此苦了一段时间,然后发现了一些对我有用的东西。 虽然不漂亮,但确实可以完成工作。
让您的存储过程返回2个记录集:一个具有所需的表数据,然后一个具有recordcount:
SELECT <all_you_need> FROM <your_table> WHERE <your_arguments>
SELECT [myCount] = @@ROWCOUNT
然后,在您的ASP文件中:
dim objRS, dataRS, countRS
Set objRS = CreateObject("ADODB.RecordSet")
Set dataRS = CreateObject("ADODB.RecordSet")
Set countRS = CreateObject("ADODB.RecordSet")
[your original call to the stored procedure]
set objRS =.Execute()
set dataRS = objRS
set countRS = objRS.nextrecordset()
countRS现在包含一个记录集,该记录集具有一行和一个名为“ myCount”的列,您可以查询该记录集以获取记录计数。 dataRS包含您的原始数据集。
注意:如果在处理数据集之前不需要知道记录数,可以这样简化:
dim objRS, countRS
Set objRS = CreateObject("ADODB.RecordSet")
Set countRS = CreateObject("ADODB.RecordSet")
[your original call to the stored procedure]
set objRS =.Execute()
[process your dataset as you need to]
set countRS = objRS.nextrecordset()