By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,534 Members | 1,807 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,534 IT Pros & Developers. It's quick & easy.

Count number of records/tuples in a database

P: n/a
What is the best way to count the number of records in a MS SQL DB.
The way I do it is executeReader() and loop through all the records in
a db and increment variable RowCount++.

Is there already a function pre-defined for it ?

Feb 18 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
weird0 wrote:
What is the best way to count the number of records in a MS SQL DB.
The way I do it is executeReader() and loop through all the records in
a db and increment variable RowCount++.

Is there already a function pre-defined for it ?
There sure is. Use the count() aggregate in a query:

"select count(*) from SomeTable"

This will return one row that contains the number of records in the table.

--
Göran Andersson
_____
http://www.guffa.com
Feb 18 '07 #2

P: n/a
Weird,

You can use instead of the executeReader the almost special command for this

Command.ExecuteScalar

http://msdn.microsoft.com/library/de...calartopic.asp

On this page you see direct the sample with the count to fulfil what you
need.

(You can do of course much more with the command)

Cor
"weird0" <am********@gmail.comschreef in bericht
news:11**********************@v45g2000cwv.googlegr oups.com...
What is the best way to count the number of records in a MS SQL DB.
The way I do it is executeReader() and loop through all the records in
a db and increment variable RowCount++.

Is there already a function pre-defined for it ?

Feb 18 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.