One About ADO Access Database Implementation Page

xiaoxiao2021-03-06  68

What is the pagination display when Ado Access Database? If you have used the electronic bulletin board on many websites, then you should know that the electronic bulletin program will not increase all the posts in one page in order to increase the read speed of the page, but will not list all the posts in one page, but will It is divided into multi-page display, and each page shows a number of posts, such as 20. Do you want to know how to implement pagination display? Please see this article! The "Dynastist Website Design Eighth War --ASP" The article has spent more than half of the year since the first phase, and believes in learning, practicing, and practical, everyone through learning, practice, re-practice, everyone It has been able to skilled the built-in object of ASP, and the ActiveX component will write some basic ASP applications. From the letter from my friends, I can feel obvious, everyone's ASP skills are constantly improving. Recently, many friends have to believe I hope that I have written some examples in reality. Therefore, from this issue, I decided to turn the positioning of "Dynamic Website Design Eighteen Wushu --asp" from the introduction and learning ASP basic knowledge to the actual operation of ASP. At the request of your friends, I will give you a question about "How to Display" when the ADO Acquisition Database is displayed. What is the pagination display when Ado Access Database? If you have used the electronic bulletin board on many websites, then you should know that the electronic bulletin program will not increase all the posts in one page in order to increase the read speed of the page, but will not list all the posts in one page, but will It is divided into multi-page display, and each page shows a number of posts, such as 20. This is the paging display of the database query. If you still don't understand, go see Yahoo and other search engines, you will understand. So how do you want to display the database's query result paging? In fact, there are many ways, but there are two: 1. Read all the records in the database in accordance with the query conditions in the database, and store them in memory, and then processed by the ADO RecordSet objects. Properties: PageSize, PageCount, and AbsolutePage (absolute page) to manage paging processing. Second, according to the customer's instruction, each time the specified number of records read from the records in accordance with the query condition, and display it. The main difference between the two is that the former is one-time to read all records into memory and then determine the effect of judgment analysis to achieve the paging display according to the instruction, and the latter is first based on the instructions and the specified number of query conditions Record read into memory, which directly reaches the features of the paging display. We can feel clearly that when the number of records in the database reaches tenstle or more, the implementation efficiency of the first method will be significantly lower than the second method, because all the customer query pages will be all Eligible records are stored in server memory, and then processed by paging, if there are more than 100 customer online queries, then the execution efficiency of the ASP application will be affected. However, when the number of records on the server and the number of online people are not many, the two are different in operation efficiency. At this time, the first method is generally used, because the ASP program of the first method is relative The second method should be much more clear. Here, the author is to analyze how our common ASP BBS programs, to analyze how to implement paging display in the BBS program, because the number of database records of the BBS program we generally use and too much access Therefore, the following program example is the first paging display method using previously described. The paging display when the ADO access database is actually operated on the record of the Recordset. So we must first learn the properties and methods of the REORDSET object: BOF properties: The current indicator refers to the first pen of Recordset.

EOF attribute: The current indicator refers to the last pen of Recordset. MOVE method: Move the indicator to a record in the Recordset. AbsolutePage Properties: Setting the location of the current record is where the ABSOLUTEPSITION property: The current indicator is in the Recordset. PageCount Properties: Displays the Recordset object that includes how much "page". PageSize Attribute: Displays the number of records displayed in each page of the Recordset object. RecordCount Properties: Displays the total number of recordset object records. Let us let us know more about these important properties and methods 1. BOF and EOF properties typically write code in the ASP program to verify the BOF and EOF properties, so that the current indicator points to the Recordset point, use BOF and EOF Attributes, you can know if a RecordSet object contains a record or knows if the mobile recording line has exceeded the RECORDSET object. Such as: <% IF not xif (rs.bof and rs.eof)%> If the current record is in front of a RECORDSET object, the BOF attribute returns TRUE, it returns false. If the current recorded position is after the last line record of a Recordset object, the EOF property returns true, and then returns false. BOF and EOF are false: indicates that the indicator is located 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 is no record in the Recordset. Second, the MOVE method You can use the MOVE method to move the indicator to a record in the Recordset, the syntax is as follows: rs.Move NumRecords, start here "rs" is an object variable, indicating a RECORDSET you want to move when the current record location Objects; "NumRecords" is a positive and negative number, setting the number of movements of the current recording location; "start" is an optional item that specifies the label of the record started. All RecordSet objects support MOVE methods. If the NumRecords parameter is greater than zero, the current record position moves in the end of the end; if it is less than zero, the current record position moves in the direction of the beginning; if an empty Recordset object calls the MOVE method, will An error will occur. MoveFirst method: Move the current recording location to the first record. MoveLAST method: Move the current record position to the last record. MoveNext method: Move the current recording location to the next record. MovePRevious method: Move the current record position to the previous record. Move [N] Method: Move indicator to the nth record, N is calculated from 0. Third, the absolutepage property The ABSOLUTEPAGE property Sets the current recorded position is the page number number; use the PageSize property to split the RecordSet object into logical pages, each page records as Pagesize (except the last page There will be less than the number of records of PageSize).

Here you must pay attention to not all data providers support this attribute, so be careful when using it. As with the AbsolutePosition property, the absolutePage property is started at 1, and if the current record is recorded as the RECORDSET, AbsolutePage is 1. The AbsolutePage property can be set to move to a first row record location of a specified page. 4. AbsolutePosition Attribute If you need to determine the current indicator in the Recordset, you can use the AbsolutePosition property. The value of the absolutePosition attribute is the current indicator relative to the first position, and the first AbsolutePosition is 1. Note that when accessset is accessed, the Recordset cannot appear in the same order each time. To enable AbsolutePosition, you must first set to use the user-end Cursor (pointer), the ASP code is as follows: rs2.cursorLocation = 3 5, the pageCount property uses the PageCount property to determine the Recordset object includes how much "page" data. The "page" here is the collection of data records, the size is equal to the setting of the PageSize property, even if the number of records in the last page is less than the value of PageSize, the last page is also a page of PageCount. It is important to note that all data providers support this attribute. 6. PageSize Attributes The PageSize property is how to make a pagination display when the ADO is used, using it to determine how much records make up a logically "one page". Set and create a size of a page to allow the use of the AbsolutePage property to move to the first record of other logical pages. The PageSize property is set at any time. Seven, RecordCount properties are also a very common and important attribute, we often use the recordcount property to find a RecordSet object to include how many records. Such as: <% = rs.recordcount%> After learning the above properties and methods of the Recordset object, let's consider how to use them to reach our pagination display. First, we can set a value for the PageSize property, specify the number of rows that make up the constituting page from the record group; then determine the total number of records through the RecordCount property; then use the total number of records to get the displayed page Total number; Finally, access to the specified page will be completed through the AbsolutePage property. It seems that it is not complicated. Let's take a look at how the program is implemented? We establish such a simple BBS application, which have the following five fields in its database: "ID", automatic number of each post; "Subject", the subject of each post; "Name", plus user Name; "email", user email address; "postdate", the time of the package. The DSN of the database is "BBS". We will display all the steps of the post paging in a process called "showlist ()", which is convenient to call.

The procedure is as follows: '---- BBS Display Post Page ---- <% Sub showlist ()%> <% pgsz = 20' setting switch, specify the number of posts displayed in each page, default is 20 sheets Set conn = server.createObject ("adodb.connection") SET RS = Server.createObject ("AdoDb.Recordset") SQL = "Select * from message order by id" "Query all posts, follow the ID of the post Conn.open "BBS" RS.Open SQL, CONN, 1, 1IF RS.Recordcount = 0 ThenRESPONSE.WRITE "

There is no relevant information in the database! " Elsers. Pagesize = CINT (PGSZ) 'Setting the value of the PageSize property Total = int (rs.recordcount / pgsz * -1) * - 1' Calculate the total number of displayed pages PAGENO = Request ("Pageno") if Pageno = "" "" " = 1elsePageNo = PageNo 1PageNo = PageNo-1end ifScrollAction = Request ( "ScrollAction") if ScrollAction = "Previous" ThenPageNo = PageNo-1end ifif ScrollAction = "Next" ThenPageNo = PageNo 1end ifif PageNo <1 Then PageNo = 1end ifn = 1RS.AbsolutePage = PageNoResponse.Write "
" position = rS.PageSize * PageNopagebegin = position-rS.PageSize 1if position database query results: "response.write "response.write" "Do while not (rs is nothing) rowcount = rs.pagesizedo while not = 1 ThenRESPONSE.WRITE" "elseresponse.write" "End IFN = 1-n%>
topic

User

Email release date
" End if if rowcount = 0 and Page NO <> Total Then Response.write ""

转载请注明原文地址:https://www.9cbs.com/read-119249.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.057, SQL: 9