Page 1 of 1
					
				Rowcount of a UniDataReader Result
				Posted: Fri  21 Jul 2017 10:54
				by magixxfactory
				Hello,
How can I got the count of rows returned by a UniDataReader ?
Thanks and regards
Uwe
			 
			
					
				Re: Rowcount of a UniDataReader Result
				Posted: Tue  25 Jul 2017 14:34
				by Pinturiccio
				A DataReader, be it UniDataReader or SqlDataReader, is not designed to get row counts. Data is read row by row, and the number of rows in the DataReader is unknown.
There are different ways to get the number of rows. Here are the two most popular and recommended ones:
1. Execute the Read method in the while cycle and increment a counter:
Code: Select all
while (reader.Read())
{
    counter++;
}
2. Load the  reader to a DataTable, and then get the number of rows from the DataTable:
Code: Select all
using (DataTable dt = new DataTable())
{
    dt.Load(reader);
    Console.WriteLine(dt.Rows.Count);
}
You can also execute the SELECT COUNT(*) query, which returns the number of rows, before reading the DataReader.