Hello,
How can I got the count of rows returned by a UniDataReader ?
Thanks and regards
Uwe
Rowcount of a UniDataReader Result
-
- Devart Team
- Posts: 2420
- Joined: Wed 02 Nov 2011 09:44
Re: Rowcount of a UniDataReader Result
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:
2. Load the reader to a DataTable, and then get the number of rows from the DataTable:
You can also execute the SELECT COUNT(*) query, which returns the number of rows, before reading the DataReader.
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++;
}
Code: Select all
using (DataTable dt = new DataTable())
{
dt.Load(reader);
Console.WriteLine(dt.Rows.Count);
}