开发者

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

开发者 https://www.devze.com 2023-01-28 17:44 出处:网络
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.

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.


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


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 * ...".


int rowCount = (int) command.ExecuteScalar();

Typo in original post by Henk.

0

精彩评论

暂无评论...
验证码 换一张
取 消