| The ASP Code |
|
The following examples will show how to count the amount of records returned in a Recordset.
Please replace 'RecordsetName' with your own Recordset name. |
|
<%
'Simple record counting using Recordset.RecordCount by Barry Wright
Dim strCount
strCount = RecordsetName.RecordCount
%> |
| The Page Code |
Place following code where you want your counter to appear. |
|
<%
'Write the total records in Recordset
Response.Write(strCount)
%> |
| |
| Known Errors |
If you receive -1 as your recordcount then it is possible that your database driver does not support this option. If this is the case then you will need to use the code below to count the records. |
| |
| Further ASP Code |
|
The following examples will show how to count the amount of records returned in a Recordset using the long method.
The Recordset count is performed by looping through the whole Recordset and counting as it goes. It is not advisable to use this method on large Recordsets, consider filtering your results first in the SQL statement used to create the Recordset. |
|
<%
'Long recordset counting using a simple loop by Barry Wright
Dim strCount
strCount = 0
While NOT RecordsetName.EOF AND NOT RecordsetName.BOF
strCount = strCount + 1
RecordsetName.MoveNext()
Wend
%>
|
| The Page Code |
Place following code where you want your counter to appear.
|
|
<%
'Write the amount of records in the Recordset
Response.Write(strCount)
%> |
| |