1. About parameter transfer. Suppose there are 46 records in the table, and then we typed http. // localhost/display. asp? In the address bar? Line = 10 & page = 2 (assuming this is the correct path) the browser will show us ten records on the second page. However, if you only enter http. // localhost/display. asp in the address bar, the browser will give us an error message. How can this problem be solved? We must add a judgment when reading these parameters. If the parameter is null, assign it an initial value to avoid errors. Use the following code to replace the "read the display method required by the user" section:
<%
If request ("page") <> "then
Page = cint (request ("page "))
Else
Page = 1' ------- if the parameter page is empty, assign it 1
End if
If request ("line") <> "then
Line = cint (request ("line "))
Else
Line = 10' ------- if the line parameter is null, assign 10 to it
End if
%>
II. Rationality of parameters. If we type http. // localhost/display. asp in the address bar? Line = 20 & page = 4 what will happen? Browser error. Because there are only 46 records in the table, and we want it to display 20 records on each page, 20 records on the fourth page, that is, 61st to 80th records. Obviously, an error occurs. In the same case, it will also appear in the navigation bar. If the current browser displays 10 entries per page and the fourth page, we will set it to display 20 entries per page, errors also occur. The solution is the same. First, judge the rationality of the parameter and then set the display mode. Use the following code to replace the "set display mode according to user requirements" section.
<%
If page> (rs. RecordCount-1) line + 1 then
'------- Through calculation, we can see that the maximum number of pages = (total number of records-1) the number of lines per page + 1
Response. write ("error! ") '------- Output" error! "
Response. end '------- terminate the program
End if
Rs. PageSize = line
Rs. AbsolutePage = page
%>
3. Verify form fields. The two input text boxes in the navigation bar must be integers. Otherwise, an error occurs. We can use the FrontPage verification form field function to complete the process.
4. Optimization. So far, this program has a disadvantage. In the database access process, the most time-consuming data is the opening of the database and the establishment of The Recordset object. Each execution of this program will open the database and create a Recordset object, this greatly reduces the efficiency. Once the access volume increases, this program is worth it. Solution: when the program is executed for the first time, open the database and create a Recordset object, and store the object in the session. During the next execution, the value in the session will be directly returned. Use the following code to replace the "open database and table" section.
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