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

Home » ASP Home » ADO Home » Database Paging

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

Search Projects & Source Codes:

Title Database Paging
Description I needed to be able to page through a database of about 1000 records and I was unable to use .AbsolutePage so I had to try something else.
Category ASP » ADO
Hits 365912
Code Select and Copy the Code
' Assumes:You will need to make a connec ' tion to your own database and re-name to ' records. <%@ Language=VBScript %> <!--#include File="_fpclass/adovbs.inc"--> <% gend = CStr(Request.QueryString("gender")) Dim iPageSize 'How many records To show Dim iRecCurrent ' The page we want To show Dim sSQL 'SQL command To execute Dim RecSet 'The ADODB recordset object Dim I 'Standard looping var Dim iRecEnd ' Last Record Dim iRecMax ' Max of record Loop Dim J ' Loop variabel Dim iRecNext ' Var of Next record To start at Dim iRecPrev ' Var of Previous record Dim sGender ' Var For displaying whether Women's or Men's race Dim iNumPage ' Number of pages ' Get parameters iPageSize = 20 ' Retrieve page to show or default to 0 If Request.QueryString("page") = "" Then iRecCurrent = 0 ' First Record Else iRecCurrent = CInt(Request.QueryString("page")) End If ' Assign value to race If gend = "Male" Then sGender = "Men's" Else sGender = "Women's" End If ' SQL statement sSQL = "SELECT * FROM 5KResults WHERE Gender='" sSQL = sSQL & gend & "' ORDER BY Time" Set RecSet = Server.CreateObject("ADODB.Recordset") RecSet.Open sSQL,"DSN=chiledadsn",adOpenForwardOnly,adLockReadOnly ' Get the count of the records Do While Not RecSet.EOF J = J + 1 RecSet.MoveNext Loop iRecEnd = J -1 ' Get the number of pages iNumPage = CInt(iRecEnd/iPageSize) ' If the request page falls outside the ' acceptable range, ' give them the closest match (0 or max) ' If iRecCurrent > iRecEnd Then iRecCurrent = iRecEnd If iRecCurrent < 0 Then iRecCurrent = 0 If iRecCurrent < iRecEnd Then iRecNext = iRecCurrent + iPageSize Else iRecNext = iRecEnd End If If iRecCurrent > 0 Then iRecPrev = iRecCurrent - iPageSize Else iRecPrev = 0 End If ' Do this so when calling the las page w ' e only loop through ' the number of records we have if less ' than the iPageSize If (iRecNext - iRecEnd ) > 0 Then iRecMax = iRecEnd - iRecCurrent Else iRecMax = iPageSize End If ' Start at the beginning of the database ' RecSet.MoveFirst 'Move to the record we want to start at RecSet.Move(iRecCurrent) ' use this when creating links ' doesn't matter what this page is named ' strScriptName = Request.ServerVariables("SCRIPT_NAME") %> <% Sub NavBar() Dim iPage Dim iVue Dim sNumbers Dim sPrev Dim sNext Dim sFirst Dim sLast Dim sNavBar Dim iLastPage iLastPage = iRecEnd - iPageSize For i = 0 To (iNumPage - 1) iPage = i * iPageSize iVue = i + 1 sNumbers = sNumbers & NavLink(strScriptName,iPage,gend,iVue) Next If iRecCurrent <> 0 Then sFirst = NavLink(strScriptName,0,gend,"First") sPrev = NavLink(strScriptName,iRecPrev,gend,"Previous") End If If (iRecCurrent + iRecMax) < iRecEnd Then sNext = NavLink(strScriptName,iRecNext,gend,"Next") sLast = NavLink(strScriptName,iLastPage,gend,"Last") End If sNavBar = sNumbers & "<BR>" & sFirst & sPrev & sNext & sLast Response.Write(sNavBar) End Sub %> <% ' Creates the link used by the navigatio ' n sub Function NavLink(scriptName,pageNum,gendr, sWord) Dim strLink strLink = strLink & "<A HREF='" strLink = strLink & scriptName strLink = strLink & "?page=" strLink = strLink & pageNum strLink = strLink & "&gender=" strLink = strLink & gendr strLink = strLink & "'>" strLink = strLink & sWord strLink = strLink & "</A> " NavLink = strLink End Function %> <HTML> <HEAD> <TITLE>5K Race Results </TITLE> <META name="description" content="An example of paging through a database."> <META name="keywords" content="Active Server Pages, ASP, database, paging"> <META http-equiv="Content-Type" content="text/html; charset=windows-1252"> <BASE target="_top"> <META name="language" content="en-us"> <META name="robots" content="INDEX"> <META name="revisit-after" content="14 days"> <META http-equiv="pragma" content="no-cache"> </HEAD> <BODY> <!-- Database Table --> <H3><% =sGender %> 5K Race</H3> <P><STRONG>Records</STRONG>: <% =iRecCurrent %> - <% = iRecCurrent + iRecMax %> of <% =iRecEnd %></P> <P><% NavBar %></P> <% ' Use these for debugging 'Response.Write ("iRecCurrent: " & iRecC ' urrent & "<BR>") 'Response.Write("iRecEnd: " & iRecEnd & ' "<BR>") 'Response.Write("iRecMax: " & iRecMax & ' "<BR>") 'Response.Write("iRecNext: " & iRecNext ' & "<BR>") 'Response.Write("iRecPrev: " & iRecPrev ' & "<BR>") 'Response.Write(CInt(iRecEnd/iPageSize) ' & "<BR>") %> <TABLE border="0" cellPadding="1" cellSpacing="0" width="425px"> <TR bgColor="blue"> <TD style="WIDTH: 130px" width="150" bgcolor="#388C40"><STRONG>Name</STRONG></TD> <TD style="WIDTH: 35px" width="35" bgcolor="#388C40"><STRONG>Age</STRONG></TD> <TD style="WIDTH: 90px" width="150" bgcolor="#388C40"><STRONG>City</STRONG></TD> <TD style="WIDTH: 35px" width="45" bgcolor="#388C40"><STRONG>State</STRONG></TD> <TD style="WIDTH: 50px" width="75" bgcolor="#388C40"><STRONG>Time</STRONG></TD> <TD style="WIDTH: 50px" width="75" bgcolor="#388C40"><STRONG>Pace</STRONG></TD></TR> <% For i = 0 To iRecMax If i Mod 2 Then Response.Write ("<TR bgColor=""#008080""><TD>") Else Response.Write("<TR><TD>") End If Response.Write(RecSet("FirstName") & " ") Response.Write(RecSet("LastName")& "</TD>") Response.Write("<TD>" & RecSet("age") & "</TD>") Response.Write("<TD>" & RecSet("City") & "</TD>") Response.Write("<TD>" & RecSet("State") & "</TD>") Response.Write("<TD>" & RecSet("Time" )& "</TD>") Response.Write("<TD>" & RecSet("Pace") & "</TD>") Response.Write("</TR>") ' Move to the next record RecSet.MoveNext Next ' Clean up after yourself RecSet.Close Set RecSet = Nothing %> </TABLE> <P><% Call NavBar %></P> <!-- End Database Table --> </BODY> </HTML>

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 | Important Websites
Copyright ©2003-2024 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=8


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