PC Review


Reply
Thread Tools Rate Thread

Count number of records/tuples in a database

 
 
weird0
Guest
Posts: n/a
 
      18th Feb 2007
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 ?

 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?G=F6ran_Andersson?=
Guest
Posts: n/a
 
      18th Feb 2007
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
 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      18th Feb 2007
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" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> 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 ?
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Count Number of Records and Number of Fields in CSV File ExcelMonkey Microsoft Excel Programming 0 29th Nov 2007 10:58 PM
Count number of records if .... mariaw Microsoft Excel Worksheet Functions 2 14th Feb 2007 09:14 AM
Count number of records in all tables in a database =?Utf-8?B?R2Vvcmdl?= Microsoft Access VBA Modules 4 11th Apr 2006 05:06 PM
Count the Number of Records RobVT Microsoft Access Forms 2 16th Nov 2005 06:10 PM
count number of records =?Utf-8?B?Sm9lX0FjY2Vzcw==?= Microsoft Access 0 13th Jan 2005 05:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:30 PM.