In Microsoft's ASP programming system, the establishment of ADO object makes it easy to access database from Web page, especially ADO Recordset object makes the output of control data display more convenient and free. In Visual InterDev6.0 (hereinafter referred to as VI6.0), because of the script Object Model (SOM), design-time Control (hereinafter referred to as DTC), and Data Environment Object Model (hereinafter referred to as DEOM), such as the introduction of such objects, so that the Web page access to the database design seems more convenient.
For the purposes of the subject, for the connection to the database, only code and brief comments are given below, focusing on how the Recordset object (or control) can be used to implement the paging display of data records. As I understand it, the key to paging display is the mastery of the properties and methods of the Recordset control of the ADO Recordset object or DTC (design-time control).
These seven types of page-showing weapons are summed up in four categories:
The first to second kind I temporarily named "Pure ASP Method", this is also the domestic ASP website uses the most method, their difference only in realizes the skill difference. The implementation of these two methods is the easiest to understand, the object concept is the least, the development environment is the minimum requirements (as long as Notepad). It can be said that the essence of these two methods or CGI programming ideas, but only in the program to introduce the ADO object.
The fourth to fifth kind is called "Som's DHTML Method". Both of these methods require the Scripting object model proposed by Microsoft in the context of VI6.0 (script objects Model) and the new features of the database binding to the Table object in DHTML (many books and articles only introduce the use of DHTML CSS features in style design without introducing their data-binding characteristics), and enable the paging on the client control. However, it requires that the user's browser must support DHTML, such as Microsoft Internet Explorer version 4.0 and above.
The sixth kind is named "Som server-side method". Required to be developed in a VI6.0 environment, it utilizes several DTC controls in the Scripting object model presented by Microsoft: Recordset, PageObject, grid, and so on on the server side (the client) to achieve page control. This is an exciting, new programming approach that looks at web pages as objects (this object model differs from traditional DOM----Document Object models: The DOM can only control the client, while the SOM controls the server side and the client), It truly implements the Object-oriented programming of the Web page. But unfortunately, perhaps my personal ability is limited, this kind of technology I personally think is not very mature, for example, the combination with the browser is not very good, this will be detailed in the later text.
The seventh kind of temporary name is called "Deom Law". It also builds the Recordset object using the Data Environment Object Model (VI6.0) established in the environment. This is also a relatively rare new method of Web programming, compared to the SOM model, has its own advantages, which will be described in detail later.
In the following all examples of the source code, can be directly copied to use, you can not even understand its principle, as long as the Bold italic character part of the corresponding to their own database name or field name on it.
Before we begin to detail the various paging methods, let's create a database: Create a employee.mdb with access in Office97, build a table EMP, set only three fields: EMP id,last name and first name. Why this is so simple, because we care about how to deal with the results of the recordset.
The first: Direct method of parameter generation
This is done by manually creating the Recordset object, using its pagesize (specify the number of records to be displayed per page), PageCount (total number of pages), and the AbsolutePage (current page number) property to control the paging output. Pagination uses the direct page numbering method to control page-flipping. The name of the Web page is emp1.asp. The source code is as follows:
<%//establishes a connection to the Employee.mdb database.
Set conn = Server.CreateObject ("ADODB. Connection ")
Conn. Open "Driver={microsoft Access driver (*.mdb)};d Bq=employee.mdb"
Create the Recordset object instance RS for the EMP table.
Set rs = Server.CreateObject ("ADODB.") Recordset ")
Rs. Open "EMP", Conn, 3
PageSize = The//pagesize property specifies the number of record bars to display per page
Page = CLng (Request ("Page")) ' String type to Long
If Page 1 Then page = 1
If Page > Rs. PageCount Then Page = Rs. PageCount
If Page <> 1 Then
Response.Write "<a Href=emp1.asp?" page=1> the first page of </A>
Response.Write "<a Href=emp1.asp?" Page= "& (Page-1) & "> prev </A> "
End If
If Page <> Rs. PageCount Then
Response.Write "<a Href=emp1.asp?" Page= "& (page+1) &" "Next page </A> "
Response.Write "<a Href=emp1.asp?" Page= "&rs. PageCount & "> Last page </A> "
End If
Response.Write "page:" & page & "/" & Rs. PageCount & "</font>"
The display of each page
Show Table Headers
Response.Write "<CENTER> <table border=1>"
Response.Write "<TR> <TD>" & Rs. Fields ("emp ID"). Name & "</TD>"
Response.Write "<TD>" & Rs. Fields ("Last Name"). Name & "</TD>"
Response.Write "<TD>" & Rs. Fields ("name"). Name & "</TD> </TR>"
Looping through each record
Rs. AbsolutePage = page//Assign page number to AbsolutePage property to know the first record number of the current page
For ipage = 1 to Rs. PageSize//
Response.Write "<TR> <TD>" & Rs. Fields ("emp ID"). Value & "</TD>"
Response.Write "<TD>" & Rs. Fields ("name"). Value & "</TD>"
Response.Write "<TD>" & Rs. Fields ("Last Name"). Value & "</TD> </TR>"
Rs. MoveNext
If Rs. EOF Then Exit for
Next
Response.Write "</TABLE> </CENTER>"%>