Counting Rows

Sometimes in your applications, you need to tell the user how many items are in a data table.

If you look at a sampling of e-commerce sites on the Internet, you will see that many of them on the home page inform the reader about how many items the site has available for purchase. This kind of information might be obtained by using an algorithm like this:

The same example written in Visual Basic looks like this:

Dim Counter As Integer = 0
While dataReader.Read
    Counter += 1
End While
dataReader.Close()

However, using this procedure in a table with many rows will take a very long time and require a great deal of resources. This slowdown ...

Get Microsoft® SQL Server™ 2005: Applied Techniques Step by Step now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.