Database Code
  Home arrow Database Code arrow ADO Recordset Paging
Iron Speed
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DATABASE CODE

ADO Recordset Paging
By: Bipin Joshi
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 32
    2003-01-01

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Many times after executing a query we get large number of records back and need to display certain number of records per page. Typically this occurs while providing search or find functionality.

    Above task can be accomplished by using ADO recordset's paging properties. Following properties are of our interest :

    • PageSize which sets the number of records per ADO recordset page
    • PageCount which gives total number of pages
    • AbsolutePage which gets/sets the current page

    Now,we will develop a sample script to demonstrate the usage. For the purpose of
    this example you should have biblio.mdb that comes with VB. For the sake of
    simplicity error handling and fine tuning is omitted.

    Following steps are involved in the process :

    1. Declare ADO recordset variable
    2. Set cursor type, location and pagesize properties
    3. Open recordset
    4. Display a list of page nummbers as hyperlinks so that when user clicks any link he will be presented with the records from that page
    5. Set current page using AbsolutePage property
    6. Display record contents from current page


    Example Code :

    <%@ Language=VBScript %>
    <% Response.Buffer=true %>

    <HTML>
    <HEAD>
    <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
    </HEAD>
    <BODY>

    <%
    dim rs,i,strConn,strTemp
    set rs=server.CreateObject("adodb.recordset")

    rs.CursorLocation=3 'clientside
    rs.CursorType=3 'staticrecordset
    rs.PageSize=100

    strConn="Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=D:\Microsoft Visual Studio\VB98\Biblio.mdb"

    rs.Open "select * from authors",strConn

    Response.Write "<table><tr>"
    for i=1 to rs.PageCount
    Response.Write "<td><ahref=paging.asp?pg=" & i & ">" & i & "</a></td>"
    next
    Response.Write "</tr></table><br>"

    if Request.QueryString("pg")="" then
    rs.AbsolutePage=1
    For i=1 to 100
    Response.Write rs.Fields("author") & "<br>"
    rs.MoveNext
    Next
    else
    rs.AbsolutePage=cint(Request.QueryString("pg"))
    For i=1 to 100
    Response.Write rs.Fields("author") & "<br>"
    rs.MoveNext
    Next
    end if

    %>

    </BODY>
    </HTML>

    Let's examine the code

    1. dim rs,i,strConn,strTemp
      set rs=server.CreateObject("adodb.recordset")

      First we declared variables for recordset,connection string and counter
      Next we reated recordset object using CreateObject method
    2. rs.CursorLocation=3
      rs.CursorType=3
      rs.PageSize=100

      The cursorlocation is set to client-side and cursor type is set to static cursor.
      Then we set the PageSize property to 100 which sets records per page to 100.
    3. rs.Open "select * from authors",strConn
      The recordset is then opened.
    4. Response.Write "<table><tr>"
      Response.Write rs.PageCount
      for i=1 to rs.PageCount
      Response.Write "<td><ahref=paging.asp?pg=" & i & ">" & i & "</a></td>"
      next
      Response.Write "</tr></table>"

      This code simply puts the links for available pages in a table. The total pages can be found out by PageCount property
    5. if Request.QueryString("pg")="" then
          rs.AbsolutePage=1
          For i=1 to 100
              Response.Write rs.Fields("author") & "<br>"
              rs.MoveNext
          Next
      else
          rs.AbsolutePage=cint(Request.QueryString("pg"))
          For i=1 to 100
              Response.Write rs.Fields("author") & "<br>"
              rs.MoveNext
          Next
      end if

      This code checks for page number selected by the user.First time when we visit
      that page it will be blank and hence we set the AbsolutePage property to 1. If
      user selects any page that page number will be assigned to AbsolutePage property.
      This causes the record pointer to move to the start of the page. We then display
      author names by scrolling through the recordset.

    In live usage, code for checking ADO errors and checking recordset EOF can be added easily.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Database Code Articles
    More By Bipin Joshi

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! IBM – Taking Web 2.0 to Work

    David Barnes, Lead Evangelist for IBM Emerging Internet Technologies will discuss aspects of Web 2.0 that bring value to corporations, academia, and government. He'll also discuss IBM's vision around Web 2.0, including the importance of remixability and consumability. The discussion will culminate with examples of various IBM Software Group solutions you can use to get ahead of the Web 2.0 adoption curve.
    FREE! Go There Now!


    NEW! Achieving True Agility -- How process can change the behavior of your tools

    Achieving true agility is a never-ending effort. We will showcase how you can become agile incrementally, a few practices at the time.Which practices should any agile team strive to adopt? What additional practices should you consider based on your needs to scale? Adopting practices are however made much easier with the right tool support. What about if your tools adapt to your practices? We will take a look at how the Jazz technology can be leveraged to make your process change the behavior of your tools.
    FREE! Go There Now!


    NEW! Don't wait! Try the Rational Application Developer (RAD) v7.5 open beta code today

    Download the Rational Application Developer (RAD) v7.5 open beta code and start developing applications for the JEE5 standard which features EJB3.0, JPA, JSF 1.2, JSP 2.1 and Servlet 2.5 standards. When you use this beta you will see how you can increase developer productivity for already existing applications with improved support for refactoring, as well as adding new features to existing applications. In addition, the beta provides tooling for JD Edwards, Oracle, SAP, Siebel and PeopleSoft to improve the developer productivity with these enterprise systems.
    FREE! Go There Now!


    NEW! Download IBM Rational Developer for System z

    Download a free trial version of IBM Rational Developer for System z, software that can help you deliver core development capabilities; the power of Java Platform, Enterprise Edition (Java EE); and rapid application development support to diverse enterprise application development teams. With comprehensive development tools to help create, deploy and maintain traditional enterprise and composite applications, Rational Developer for System z enables developers with different technical backgrounds to easily participate in important technology projects.
    FREE! Go There Now!


    NEW! Improve your build process with IBM Rational Build Forge, Part 1: Create a continuous build and integration environment

    Learn how to implement a build management system that uses and extends your existing automation technologies. This tutorial shows, step-by-step, how to install and configure IBM Rational Build Forge to manage builds for Jakarta Tomcat from source code.
    FREE! Go There Now!


    NEW! Info 2.0: Harnessing the power of Web 2.0 and Enterprise Mashups

    Listen to this webcast to get an overview of Info 2.0 and a technical demo of how to quickly build an enterprise mashup. IBM's Info 2.0 technology leverages emerging Web 2.0 technologies such as mashups, feeds, AJAX, and JSON in order to simplify assembly of information using feeds and services. Come learn about the technical elements of Info 2.0 including the Feed Generation framework, Mashup Engine, and mashup assembly components. Learn how to pull information from databases, departmental information, and the Web to create mashups critical to your company’s success. We will also discuss best practices to help you get started.
    FREE! Go There Now!


    NEW! Try the IBM SOA Sandbox for People

    Visit IBM developerWorks to try the IBM SOA Sandbox for people. The SOA Sandbox for people provides a trial environment with the necessary tooling and components required to enable consistent human and process interaction and collaboration, showing how you can improve user experience and business productivity.
    FREE! Go There Now!


    NEW! Web development with Eclipse Europa, Part 3: Ruby Development Toolkit and RadRails

    It's a good time to be a Web developer. You've never had more choices in terms of technologies. There are so many great open source Web servers, databases, programming languages, and development frameworks. No matter what combination of technologies you prefer to work with, there is a single integrated development environment (IDE) that can increase your productivity: Eclipse. Here in Part 3, we introduce the RDT and RadRails Eclipse plug-ins and show you how to get these plug-ins and start using them. You will learn how to use RadRails to do many common Ruby on Rails development tasks.
    FREE! Go There Now!


    NEW! Webcast: Eclipse: Empowering the universal platform

    The Eclipse community is constantly working to extend Eclipse's functionality. In this webcast, learn about some of the most important and feature-rich projects under development. From multi-language support to plug-in development, tune in to see what Eclipse is capable of now.
    FREE! Go There Now!


    NEW! Webcast: Extreme transaction processing with WebSphere Extended Deployment

    In this webcast, you'll get an introduction to the eXtreme Transaction Processing (XTP) features of WebSphere Extended Deployment and the common architectural traits required by XTP applications. See how WebSphere Extended Deployment's ObjectGrid feature provides a state-of-the-art infrastructure for hosting XTP applications.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    DATABASE CODE ARTICLES

    - Deployment of the MobiLink Synchronization M...
    - MobiLink Synchronization Wizard in SQL Anywh...
    - Finding Matching Records in Data Access Pages
    - Using the AccessDataSource Control in VS 2005
    - A Closer Look at ADO.NET: The Command Object
    - A Closer Look at ADO.NET: The Connection Obj...
    - Using ADO to Communicate with the Database, ...
    - Code Snippets: Counting Records
    - Constraints In Microsoft SQL Server 2000
    - Multilingual entries into a DB and to be dis...
    - Getting A List of Tables From SQL Server
    - SQL Server Database Creator - .NET Version
    - ADO Recordset Paging
    - Two combos, one textbox example
    - Discussion & Listserv Module by Mike Eck...

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway