When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles [1.x] [2.0]
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips
Search

Sections:
Book Reviews
Sample Chapters
Commonly Asked Message Board Questions
Headlines from ASPWire.com
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
Web Hosts
XML Info
Information:
Advertise
Feedback
Author an Article
Technology Jobs

















internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers
ASP ASP.NET ASP FAQs Message Board Feedback ASP Jobs
Print this page.

Windows Systems Administrator
Jupitermedia
US-CT-Darien

Justtechjobs.com Post A Job | Post A Resume

Published: Sunday, November 29, 1998

Recordset Cursors: Choose the Right Cursor for the Right Job


When you explicitly create a recordset object in ADO, you can specify what type of cursor you want it to employ. By explicitly creating a recordset, I mean that you issue the following command:

- continued -

Set rs = Server.CreateObject("ADODB.Recordset")

You can always implicitly create a recordset object, and most often developers do just that. For example, if we were to run the following code:

Dim rs, conn
Set conn = Server.CreateObject("ADODB.Connection")

'Open the connection using an Application-level
'connection string
conn.Open Application("Connection_String")

Set rs = conn.Execute("SELECT * FROM pubs")

After the last line is executed, you have a bona fied recordset object in rs. It was created implicitly by ADO / ASP, and has a forward-only cursor. When you explicitly create a recordset object, however, you can choose what type of cursor you wish to employ by using the following line of code:

rs.CursorType = 'Enter cursor type here

The cursor type can be one of four types:

  • Forward-only
  • Static
  • Keyset
  • Dynamic

A forward-only cursor is the cursor with the least amount of overhead, thus leading to the best performance. It is also the default cursor for a recordset. It's only flaw is that it is uni-directional. You can only use commands which iterate through the recordset from front to end, such as MoveNext. You cannot use MovePrev, for example. If you try to issue a MovePrev command on a forward-only recordset you will get an error explaining that you cannot perform such an operation on a firehose cursor. (It is called a firehose cursor because like a hose, the stuff (records, in a recordset, water in a hose) is only going one way.) To use a forward-only cursor, you could type:

rs.CursorType = adOpenForwardOnly

Note: This article assumes you include adovbs.inc on each of your ASP pages. If you need the file it can be downloaded by clicking on the hyperlink.

The next type of cursor is a static cursor. This allows you to move in any direction, but it doesn't reflect any updates, deletions, or additions to the recordset while the user is viewing the recordset. It is as if a snapshot was taken of the data at the time it was requested. This recordset let's you use the full plethora of recordset traversal commands, such as MoveFirst, MovePrev, MoveLast, RecordCount, and others. You can use a static cursor by typing:

rs.CursorType = adOpenStatic

Dynamic and Keyset cursors allow you to see any changes which are made. While this is nice in a VisualBASIC application, it really doesn't apply to the web, since a request is made, and, like the static cursor, a snapshot of the information is brought back. There is no way to continuously update the data for the client without having the client refresh his screen (unless you delve into some of IE 4.x's new data features). Since this is the case for the web, you should never use Keyset or Dynamic cursors, since they hog up more resources than Static or forward-only. If you need to traverse through your recordset or need a count of your recordset, use a static cursor, else use a forward-only cursor

Using a forward-only cursor when only a forward iteration through a recordset is needed will save system resources and decrease query time. For that reason, be sure to choose the right cursor when you create your recordsets!

Happy Programming!


Windows Internet Technology | ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Microsoft Article: 7.0, Microsoft's Lucky Version?
Microsoft Article: Hyper-V--The Killer Feature in Windows Server 2008
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Windows Server 2008
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES