Classic ASP - Stored procedure to recordset returns “-1” records?

假如想象 提交于 2019-12-11 09:37:22

问题


I am trying to execute a stored procedure using Classic ASP, with two parameters and return the results into a record set that I can loop through and display into a table via a DO WHILE loop.

The problem is, however, I do not get any results when I try and execute the below code. When I use the "RecordCount" property it returns -1 records.

Normally if it were a standard SQL query I would use Response.Write to get the query text and diagnose in SSMS, but i'm not sure how I can troubleshoot when using ADODB.Command. Is there a way to write out exactly what it is doing?

Here is what I have:

Set cmd = Server.CreateObject("ADODB.Command") 
Set objRS = Server.CreateObject("ADODB.RecordSet")
With cmd 
    .ActiveConnection = objConn 
    .CommandType = 4
    .CommandText = "dbo.testCount" 
    Call .Parameters.Append(.CreateParameter("@Location", adVarChar, adParamInput, 50))
    Call .Parameters.Append(.CreateParameter("@Year", adInteger, adParamInput))
    .Parameters("@Location").Value = "TestLocation"
    .Parameters("@Year").Value = 2014
    Set objRS = cmd.Execute()
    End With
    Set cmd = Nothing
    TotalRecords = objRS.RecordCount
    Response.Write TotalRecords

^^^^ TotalRecords = "-1" .. ?

来源:https://stackoverflow.com/questions/26832839/classic-asp-stored-procedure-to-recordset-returns-1-records

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!