Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RecordCount 1

Status
Not open for further replies.

eyal

Programmer
May 15, 2000
38
IL
How do I count the number of records in a table?
 
Hi eyal,<br>Write the select statement &quot;select count(*) from table_name&quot;. and crete a recordset object with this statement. <br>This will give the count of records in the data base table.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;or else<br>create a record set with the cursor type other than forward-only type. Use the select statement to access all the values from the table and use the recordset's recordcount property to get the no of records. If the value u got is -1, it means that the provider used to access the data base is not supporting the recordcount property. In this case you can use the earlier methid.<br><br>I can give you the code if you want
 
Hi,<br>First, thanks for your reply, since I'm new to ASP I'll appreciate you sending me the code so I can implement it in my code.<br>Thanks again,<br>Eyal
 
Hi,<br>Write the following code in the asp page.<br>&lt;%<br>set objconn = server.createobject(
 
Hi,<br>Write the following code in the asp page.<br>&lt;%<br>set objconn = server.createobject(&quot;adodb.connection&quot;)<br>objconn.open &quot;dsn=testdsn;uid=sa;pwd=;&quot;<br>set objrec = server.createobject(&quot;adodb.recordset&quot;)<br>objrec.cursortype = adopenkeyset<br>strsql = &quot;select * from table1&quot;<br>objrec.open strsql,objconn<br>reccount = objrec.recordcount<br>response.write &quot;No of records in the table=&quot; & reccount & &quot;&lt;br&gt;&quot;<br>objrec.close<br>set objrec = nothing<br>objconn.close<br>set objrec = nothing<br>%&gt;<br><br>Before excuting this code create a system DSN. Follow these steps to create one.<br>From start --&gt; settings --&gt; control panel --&gt; odbc data sources --&gt; select System DSN<br>--&gt; click add --&gt; select the driver --&gt; give DSN name as testdsn --&gt; advanced button --&gt; userid = sa and password keep empty --&gt; select the data base --&gt; click OK.<br>The steps to create a DSN will be different for different data bases. The above ones are for Access database.
 
Well kirankumar, it didn't work, I got the -1.<br>Can you send me the first method code?<br>Thanks<br>Eyal<br>
 
Hi eyal,<br>here is the alternate code<br>&lt;%<br>set objconn = server.createobject(&quot;adodb.connection&quot;)<br>objconn.open &quot;dsn=testdsn;uid=sa;pwd=;&quot;<br>set objrec = server.createobject(&quot;adodb.recordset&quot;)<br>strsql = &quot;select count(*) from table1&quot;<br>objrec.open strsql,objconn<br>reccount = objrec(0)<br>response.write &quot;No of records in the table=&quot; & reccount & &quot;&lt;br&gt;&quot;<br>objrec.close<br>set objrec = nothing<br>objconn.close<br>set objrec = nothing<br>%&gt;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top