如何统计ASP经典中的记录?

3 asp-classic

我不太熟悉ASP经典编程.我只需要在我的网页上运行一个小代码.我如何计算返回查询的记录?

<%
Set rsscroll = Server.CreateObject("ADODB.Recordset")
Dim strSQLscroll, rsscroll
strSQLscroll = "SELECT * FROM tblItems where expiration_date > getdate() order by expiration_date desc;"
rsscroll.open strSQLscroll,oConn
%>
Run Code Online (Sandbox Code Playgroud)

谢谢,

Bor*_*att 8

可以(但不推荐)在Recordset对象上使用RecordCount属性,如下所示:

iTotalRecords = rsscroll.RecordCount
Run Code Online (Sandbox Code Playgroud)

如果您的表格非常大,则可能需要很长时间才能运行.我会改为运行一个单独的SQL查询来获取总记录

SQL = "SELECT COUNT(*) AS TotalRecords FROM tblItems WHERE expiration_date > getdate() "
set rsRecordCount = conn.Execute(SQL)
if not rsRecordCount.Eof then
  iTotalRecords = rsRecordCount.Fields("TotalRecords")
else
  iTotalRecords = 0
end if
rsRecordCount.Close
set rsRecordCount = nothing
Run Code Online (Sandbox Code Playgroud)


Chr*_*eis 6

rsscroll.总记录

  • 那可能有效,但也可能返回-1。例如,默认的SQL Server firehose行集在调用者使用完所有记录之前不会产生行数。 (2认同)