A datareader is a "connected" data object. This means it is constantly connected to the database as long as it's open in the code. This makes it faster, but has the drawback that it only gets the data that is required as it is requested. As a result, you can't ask it how many records there are for a given query because it doesn't know. It only knows that it has reached the end of the requested set when it asks the database for the next record (DataReader.Read()) and that method call returns false.
In order to get a complete set of data and be able to determine the number of rows, you need to work with a "disconnected" data object, such as the DataTable. A DataTable has a rows collection which has a count property.
-
Peter