Add to Favorites    Make Home Page 27241 Online  
 Language Categories  
 Our Services  

Home » ASP Home » SQL Home » Count Records

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title Count Records
Description This script counts the records in a database. Many people who attempt to use the .recordcount property have the value -1 returned to them. In a nutshell, -1 means "I don't know how many records this query/table contains". It happens since the default cursor type is AdOpenforwardonly (see below for explanation of all cursor types). Here is the script that counts the query results and WILL NOT return -1:
Category ASP » SQL
Hits 5778
Code Select and Copy the Code
<head><html> <TITLE>dbcount.asp</TITLE> </head><body bgcolor="#FFFFFF"> <!--#INCLUDE VIRTUAL="/ADOVBS.INC" --> <% ' change these for your site connectme="DSN=Student;uid=student;pwd=magic" sqltemp="select * from publishers where state='NY'" Set rstemp=Server.CreateObject("adodb.Recordset") rstemp.open sqltemp, connectme, adopenstatic howmanyrecs=rstemp.recordcount Response.Write howmanyrecs & " records in<br>" & sqltemp rstemp.close Set rstemp=Nothing %> </body></html> The critical part here Is having a cursor Type that supports it (Adopenforward only Is the default cursor Type And it does Not support counting records) And including adovbs.inc To define the cursor types. The file adovbs.inc can be obtained from http://www.learnasp.com/adovbs.inc If you Open the database And are able To obtain an accurate record count Is by nature a slower connection; it Is a burden On a recordset that it must know exact record counts upon demand. The additional overhead And limitations of a adopendynamic Or adopenstatic cursor may be a glacially slow way To retrieve the data even though they count accurately. If you must count And retrieve, you can't go wrong using GetRows (see http://www.learnasp.com/learn/dbtablegetrow.asp) because: GetRows can count With any cursor Type And Is very fast at retrieving And counting! Is much faster And conserves server resources, see: /advice/whygetrows.asp Here Is a description of the significance of Each cursor Type: Adopenstatic cursor The data Is dead. If you retrieve a million records For example at 9:00am And it takes 6 minutes To read the data, at the 6th Minute you will Not be retrieving fresh Or recently added data. It Is like a snapshot of the data. Recordsets opened this way WILL contain an accurate recordcount. Adopenforwardonly cursor (the default) The data Is alive but you can only move forward. Attempts To move backward Or To specific record numbers will fail.. Recordsets opened this way WILL Not contain an accurate recordcount, instead returning -1. Adopenkeyset cursor The data Is alive And any record read will be the most recent data. f you retrieve a million records For example at 9:00am And it takes 6 minutes To read the data, at the 6th Minute you will still be retrieving fresh data but Not data added Or deleted since 9am. Recordsets opened this way WILL Not contain an accurate recordcount, instead returning -1. Adopendynamic cursor The data Is alive And additions will be noticed. If you retrieve a million records For example at 9:00am And it takes 6 minutes To read the data, at the 6th Minute you will still be retrieving fresh data And records added To the End of the data. Recordsets opened this way WILL contain an accurate recordcount.

Related Source Codes

Script Name Author
ııııııııııııııııııııı VyomWorld
Resistor color code reader A.Chermarajan.
Telephone Directory dhivya
card swapping game (Mini Project) nityanand
simple hangman-pascalsource Seabert
college dirtectory (Mini Project) msridhar
Poll Application John van Meter
ASP Daily Hit Counter. Tejaskumar Gandhi
To avoid null in asp environment using sql Sami
Maklumbalas webmaster
poll John van Meter
EasyASP Template Engine. TjoekBezoer
Basic Calculator using HTML & Javascript. Patrick M. D Souza
What servers support ASP ? VyomWorld
What is ASP? VyomWorld

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions
Copyright ©2003-2019 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=220


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review