If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > How will i know how many rows are there in a table?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-30-04, 08:20
cody7 cody7 is offline
Registered User
 
Join Date: Mar 2004
Posts: 8
How will i know how many rows are there in a table?

adoRS.Open "select * from table_name"

numField = adoRS.Fields.Count
response.write("Number of Filed of table_name = "&numFiled)

my question is....

how will i know how many rows are there in table_name?
is there a

numRows = adoRS.Rows.Count

any help with this?...... tnx
Reply With Quote
  #2 (permalink)  
Old 04-30-04, 11:54
Seppuku Seppuku is offline
Useless...
 
Join Date: Jul 2003
Location: SoCal
Posts: 721
You could either do it in a select statement:
Code:
SELECT Count(ID) AS TotalRows FROM table_name
(where "ID" is your key field)

Or you could try:
Code:
adoRS.MoveLast
adoRS.MoveFirst
numRows = adoRS.RecordCount
Or the brute force way:
Code:
If NOT adoRS.BOF AND NOT adRS.EOF Then
  WHILE NOT adoRS.EOF
    numRows = numRows + 1
    adoRS.MoveNext
  WEnd
  adoRS.MoveFirst
End If
__________________
That which does not kill me postpones the inevitable.
Reply With Quote
  #3 (permalink)  
Old 05-03-04, 00:24
thele thele is offline
Registered User
 
Join Date: Jun 2003
Location: Ohio
Posts: 108
Seppuku,

Why do you have to do a MoveLast, then Movefirst before doing the count, in your second example?
Reply With Quote
  #4 (permalink)  
Old 05-03-04, 00:30
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
because he hasn't specified the recordset cursor type or the database he is going to so he doesn't know what how the recordcount property will behave...

If you move to the last record in most cases you can be sure your recordcount will be accurate.
Reply With Quote
  #5 (permalink)  
Old 05-03-04, 11:30
Seppuku Seppuku is offline
Useless...
 
Join Date: Jul 2003
Location: SoCal
Posts: 721
Right. I was playing it safe.
__________________
That which does not kill me postpones the inevitable.
Reply With Quote
  #6 (permalink)  
Old 05-12-04, 04:48
asdf asdf is offline
Registered User
 
Join Date: Apr 2002
Posts: 4
Using the recordcount property of the recordset object you can find out the number of records in a table.
Reply With Quote
  #7 (permalink)  
Old 05-12-04, 04:50
asdf asdf is offline
Registered User
 
Join Date: Apr 2002
Posts: 4
Using the recordcount property of the recordset object, you can find out the number of records in a table.
Reply With Quote
  #8 (permalink)  
Old 05-12-04, 11:14
Seppuku Seppuku is offline
Useless...
 
Join Date: Jul 2003
Location: SoCal
Posts: 721
That has already been stated asdf.
__________________
That which does not kill me postpones the inevitable.
Reply With Quote
  #9 (permalink)  
Old 05-12-04, 14:39
gyuan gyuan is offline
Registered User
 
Join Date: Dec 2003
Posts: 454
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.ConnectionString = MyConnectionString
Conn.Open
Set RS = Server.CreateObject("ADODB.RecordSet")
RS.CursorLocation = adUseClientBatch
SQL = "SELECT * FROM MyTable"
RS.Open strSQL, Conn, adOpenStatic
TotalRowNumber = RS.RecordCount
...
Set RS = Nothing
Set Conn = Nothing
Reply With Quote
  #10 (permalink)  
Old 05-12-04, 22:32
sundialsvcs sundialsvcs is offline
Registered User
 
Join Date: Oct 2003
Posts: 706
The bottom line is:
  • If you want to know the number of rows in a table, use SELECT COUNT(*) FROM tablename.
  • If you have issued a query and want to know how many rows are in the result, you must use MoveLast before examining the Count. The reason is that the SQL-engine might deliver the first page of results to you before it has actually finished the entire query.
If you can possibly avoid it, don't go for that record count. Not unless you need it for some purpose other than giving the user an "interesting" number. Either (a) you are running a redundant query (and an expensive one at that), or (b) you're forcing the user to wait for full query completion (and... forcing the DBMS to actually complete it) ... all to produce, "an interesting but expensive number."
__________________
ChimneySweep(R): fast, automatic
table repair at a click of the
mouse! http://www.sundialservices.com
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On