Ajay_Kumar
Ajay_Kumar

Reputation: 1387

how to count the total number of row in oledbconnection in c#.net

how to count the total number of row in oledbconnection in c#.net

I want to count how many rows are present in my table.

                string dataReader = "SELECT count(*) from `Email_account_list`";
                OleDbCommand command_reader = new OleDbCommand(dataReader, myConnection);
                OleDbDataReader row_reader = command_reader.ExecuteReader();

What function i will write to fetch total number of rows present in table.

Upvotes: 4

Views: 18949

Answers (2)

Henk Holterman
Henk Holterman

Reputation: 273844

A SELECT COUNT(*) statetment is a special (SELECT) statement in that you should not use ExecuteReader() but instead use int rowCount = (int) command.ExecuteScalar();

Upvotes: 11

Hans van Dodewaard
Hans van Dodewaard

Reputation: 713

Use "Select count(*) ..." first in your OleDbCommand. This will give you an idea of the number of rows you could expect in the next "Select * ...".

Upvotes: 0

Related Questions