Click here to Skip to main content
15,942,376 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a query that get the data from multiple tables now i have to count the total number of records,i can get number of records by filling the table into DataTable object e.g dt.Rows.Count,but table contains 1 million records so it takes time to fill data.
Thanks in advance.


Use @@ROWCOUNT in your select statement. like,

select @@ROWCOUNT,col1,col2..... from ... join.....
Share this answer
USe new query for count the record

Select Count(*) From ...your select statment

In this way you will not have to wait the time to fill the datatable.
Of course this leads to a double select the database.
Share this answer
I solved this problem by using CTE(Common Type Expressions)
first i create CTE name cte
like e.g:
string cte=";with mycte as(my statement that take data from multiple table)"
select count(*) from mycte;

note:CTE start with semicolon
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