Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

How to get the total record count after executing the reader.

see my code
------------
Conn.Open()
Qry = ""
Qry = "Select * from employee order by Emp_name"
Cmd.Connection = Conn
Cmd.CommandText = Qry
Rdr = Cmd.ExecuteReader

How to get the Total Record Count...?
Posted

THe simplest way would be to run a loop on the reader and simultaneously count rows in a variable ->
if (dr.HasRows) {  
int count = 0;     
while (dr.Read()) {     
count++;  
}     


Now count will contain the number of records.
 
Share this answer
 
You will have to loop through the reader to find out the number of rows.
C#
int count = 0;
while (Rdr.Read())
{
    count++;
}
//check the value of count here. This will be the number of rows returned.


Hope this helps!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900