Click here to Skip to main content
14,865,252 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

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

see my code
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...?

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

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

Hope this helps!

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