I'm working with a SQL Server stored procedure in Classic ASP with 3 parameters. I am attempting to find the recordcount, but it returns '-1'.
I saw a similar post, did what it suggested (check cursortype, and add 'set nocount on' in the stored procedure), but those changes did not impact the -1 recordcount.
Here is my code in the Classic ASP page, below.
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
Here is the code for the stored procedure, below:
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