Rowcount of a UniDataReader Result

Rowcount of a UniDataReader Result

Postby magixxfactory » Fri 21 Jul 2017 10:54

How can I got the count of rows returned by a UniDataReader ?
Thanks and regards
Posts: 11
Joined: Fri 27 Aug 2010 18:24

Re: Rowcount of a UniDataReader Result

Postby Pinturiccio » Tue 25 Jul 2017 14:34

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())

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())

You can also execute the SELECT COUNT(*) query, which returns the number of rows, before reading the DataReader.
Devart Team
Posts: 1981
Joined: Wed 02 Nov 2011 09:44

Return to dotConnect Universal