Detailed pagination display when ADO accesses a database

Source: Internet
Author: User
Tags first row server memory
ado| Pagination | data | database | What is the paging display when ADO accesses the database? If you've ever used a lot of electricity on the web today,

Sub Bulletin Board program, then you should know the electronic bulletin board program in order to improve the reading speed of the page,

Generally not all of the posts are listed in a page, but it is divided into multiple pages, each page
Displays a certain number of posts, such as 20. Do you want to know how to implement a paging display? Please see
This paper!
So how exactly can you do to the database query results page display it? In fact, there are many ways,

But there are two main types:
First, all records that meet the query criteria in the database are read into the recordset at once,

stored in memory, and then through the ADO Recordset object provided by several specialized support paging office
Attributes: PageSize (page size), PageCount (number of pages), and
AbsolutePage (Absolute page) to manage paging processing.
Second, according to the customer's instructions, each time from the records to meet the requirements of the record will be the number of notes
The recorded number is read and displayed.
The main difference between the two is that the former is a one-time read all the records into memory and then according to the instructions
In order to make a judgment analysis to achieve the results of pagination, the latter is based on the instructions to make judgments and
The specified number of records that match the query criteria are read into memory, which directly achieves the function of paging display.

We can clearly feel that when the number of records in the database reaches tens of thousands or more, the first
The execution efficiency of the method will be significantly lower than the second method, because every customer queries the page
Store all eligible records in server memory, and then handle paging, if
With more than 100 customer inquiries online, the efficiency of ASP applications will be greatly affected by
Effect. However, when the number of database records on the server and the number of people online are not many,
The efficiency of the two is the same, at this time the first method is generally used, because the first
Method of ASP program writing is much simpler and more straightforward than the second method.
Here the author of our common ASP BBS program as an example, to give you an analysis of how to
In the BBS program to achieve the paging display function, due to our general use of the BBS program database
Both the number of records and the number of people who have access are not too many, so the following program instance is used as described previously
The first way to display pagination.
When you make ADO access to the database, the paging display is actually a record of the recordset
to operate. So we first have to understand the properties and methods of the Reordset object:
BOF attribute: Current indicator refers to the first pen in the RecordSet.
EOF attribute: The current indicator refers to the last stroke of the RecordSet.
Move method: Moves the metric to a record in the recordset.
AbsolutePage Property: Sets the location of the current record in which page
AbsolutePosition property: The position of the current indicator in the RecordSet.
PageCount property: Displays data about how many "pages" the Recordset object includes.
PageSize Property: Displays the number of records displayed on each page of the Recordset object.
RecordCount Property: Displays the total number of Recordset object records.
Let's take a detailed look at these important attributes and methods
First, BOF and EOF attributes
In general, we write code in an ASP program to verify the BOF and EOF attributes, thus knowing
The location of the RecordSet pointed to by the current indicator, using the BOF and EOF attributes, can be learned
Whether a Recordset object contains records or whether the move record row has exceeded the
The scope of the Recordset object.
such as: <% if not rs.eof then ...%>
<% if not (Rs.bof and rs.eof)%>
If the current record is located before the first row of a Recordset object is recorded, BOF
property returns True, or false on the contrary.
If the current record is located after the last row of a Recordset object is recorded,
The EOF property returns True, whereas false is returned.
BOF and EOF are False: Indicates that the indicator is in the RecordSet.
BOF is True: The current indicator refers to the first record of the recordset.
EOF is True: The current indicator refers to the last record of the recordset.
BOF and EOF are True: There are no records in the recordset.
Two, Move method
You can move the metric to a record in the recordset using the motion method, as follows:

Rs. Move Numrecords,start
Here the "RS" is an object variable that represents the one that wants to move the current record position.
Recordset object; "NumRecords" is a positive negative expression that sets the current record position
The number of moves; "Start" is an optional item that specifies the label at which to start the record.
All Recordset objects support the Move method, if the NumRecords parameter
is greater than 0, the current record position moves toward the end, and if it is less than 0, the current record position
Moves toward the beginning; If an empty Recordset object calls the Move method, it will
An error has occurred.
MoveFirst method: Moves the current record position to the first record.
MoveLast method: Moves the current record position to the last record.
MoveNext method: Moves the current record position to the next record.
MovePrevious method: Moves the current record position to the previous record.
Move [n] Method: Moves the metric to the nth record, and N is counted from 0.
Third, AbsolutePage properties
The AbsolutePage property sets the number of pages on which page the current record is located;
Use the PageSize property to split the Recordset object into logical pages, with records for each page
Number is PageSize (except that the last page may have fewer than PageSize records). Over here
It is important to note that not all data providers support this property, so be careful when you use it.
The AbsolutePage property is the same as the AbsolutePosition property, starting with 1
, if the current record is the first row of the Recordset, AbsolutePage is 1. OK
Sets the AbsolutePage property to move to the first row record position on a specified page.
Four, AbsolutePosition property
If you need to determine the position of the current indicator in the RecordSet, you can use the
AbsolutePosition property.
The value of the AbsolutePosition property is the current indicator relative to the position of the first pen, by 1
The absoluteposition of the first stroke is 1.
Note that when you access a recordset, you cannot guarantee that the recordset will always have the same
Order appears.
To enable AbsolutePosition, you must first set up to use the client
Cursor (pointer), ASP code is as follows:
Rs2. CursorLocation = 3
Five, PageCount properties
Use the PageCount property to determine how many "pages" of data the Recordset object includes.
The "page" Here is a collection of data records, the size of which is equal to the setting of the PageSize property, even if the last
The number of records on a page is less than PageSize, and the last page is a PageCount page.
It is important to note that not all data providers support this property.
Six, PageSize property
The PageSize property is the key to determining how ADO is paged when it accesses a database, using it
You can decide how many records make up a logically "one page". Set and build a page size,
This allows you to move to the first record of another logical page using the AbsolutePage property.
PageSize properties can be set at any time.
Vii. RecordCount Properties
This is also a very common and important attribute, and we often use the RecordCount property to find out
How many records a Recordset object includes. Such as:
<% Totle=rs. RecordCount%>
Once you've learned more about the attributes and methods of the Recordset object, let's consider the
How to use them to achieve the purpose of our paging display. First, we can give the PageSize property
Sets a value that specifies the number of rows that make up a page from the group of Records;
RecordCount property to determine the total number of records, and then use the total number of records divided by PageSize to
To the total number of pages displayed; Finally, you can complete access to the specified page through the AbsolutePage property
As if it's not complicated, let's take a look at how the program should be implemented.
We build such a simple BBS application, its database has the following five
Fields: "ID", the automatic number of each post, "subject", the subject of each post;
"Name", add the user's name, "email", the user's e-mail address;
"Postdate", add the time of the post. The DSN for the database is "BBS". We will show the posts
All steps of pagination are placed in a process called "showlist ()" for easy invocation.
The procedure is as follows:

'----BBS Display posts paging----
<% Sub Showlist ()%>
<%
Pgsz=20 ' Set switch, specify the number of posts displayed on each page, default to 20 posts a page
Set Conn = Server.CreateObject ("ADODB. Connection ")



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.