I want to get the retrived records count from the OleDbDataReader
in C# ?
strQuery = "SELECT * FROM Table_Name" ;
dbCommand = new OleDbCommand(strQuery, dbConnection);
dbReader = dbCommand.ExecuteReader();
//Now how to get RowCount from the Table after this.
Any help is appreciated.
Thanks.
For more detail : Get row count by 'ExecuteScalar'
Make use of ExecuteSclar()
rather than going for read
function.
SqlCommand cmd = new SqlCommand("SELECT count(*) FROM " + Table_Name, conn);
try
{
conn.Open();
int total = (Int32)cmd.ExecuteScalar();
}
You could change the query to:
strQuery = "SELECT count(*) as RowCount, * FROM " + Table_Name;
That would allow you to retrieve the rowcount like:
dbReader.Read();
var rowCount = (int)dbRead["RowCount"];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With