Counting Records in a Recordset
Written by Eric Smith, Northstar Computer Systems LLC
There are a number of ways to get a record count from a recordset; however, the most efficient way is to let the database do the work for you, as shown here:
<%
Dim dcnDB ‘ As ADODB.Connection
Dim rsData ‘ As ADODB.Recordset
Set dcnDB = Server.CreateObject(“ADODB.Connection”)
dcnDB.Open “connection string goes here”
Set rsData = dcnDB.Execute(“SELECT COUNT(*) FROM tblCustomers”)
Response.Write “Record count is “ & rsData(0) & “.”
rsData.Close
dcnDB.Close
%>
If you need to loop through the records afterward, it is better to close the recordset and then reopen it using the appropriate type of cursor for the situation.
Keywords: [
Uncategorized ASP Tips
]
Publication Date: 10/1/1999
|