Recommended: ASP instance tutorial: FileSystemObject Object Does the file specified by the FileSystemObject object exist? This example demonstrates how to first create a FileSystemObject object, and then use the FileExists method to detect whether a file exists. The code of this example is as follows: The following is the referenced content: html body %Set fs=Server.CreateObject(Scripting.FileSystemObject) If (fs.F
Regarding the phenomenon of negative numbers during Recordset paging, I believe many people have encountered this problem. Sometimes Baidu and GOOGLE are not solved. Let me summarize it now.
Negative numbers appear mainly related to the cursor type. (For the convenience of example, suppose there is already a file that conn.asp links the database and has included) Now give an example, the code is as follows:
'============================================================================
sql=Select * from table name where condition order by ID desc 'The order by condition here can be rewritten according to your needs
Set rs=conn.execute(sql) '=== Pay attention to this sentence===
rs.pagesize=10 '===Set the number of records per page to 10===
page=request.querystring(page)
If page= Then page=1
If Not IsNumeric(page) Then page=1
page=clng(page)
If page<1 Then page=1
If page>rs.pagecount Then page=Vrs.pagecount
rs.absolutepage=page
dim c
c=1
Do while Not rs.eof And c<=rs.pagecount
'Output content
c=c+1
rs.movenext
Loop
'Make a link to the page
'============================================================================
According to the above code, the RecordSet object is directly composed of the code: Set rs=conn.execute(sql). After using this sentence, the default cursor of the RecordSet object is 0, that is, the cursor can only scroll forward, and the lock type is 0, indicating that it is read-only locked and cannot update the RecordSet object.
Therefore, if a negative number occurs during paging, check whether the RecordSet object is written in the above form, and write it as:
Set rs=Server.CreateObject(adodb.recordset)
rs.open sql,conn,1,3
The above means that the cursor is 1, which can move forward and backward; the lock type is 3, which can update multiple records in batches.
There will be basically no problem according to the above method, but for insurance, according to the principle of RecordSet paging, it is to obtain the number of records based on reading all records, so first let the cursor scroll around and add the following two sentences after level rs.pagesize=10:
rs.movelast 'cursor moves to the last
rs.movefirst 'cursor moves to the front
It is known that the pagination principle of RecordSet is to read out the records in the entire database before obtaining the value of rs.Recordcount (total records). This pagination method is relatively simple, but it has a fatal disadvantage. When there are many records in the database, according to its pagination principle, it will occupy a lot of system resources and is very wasteful. It is recommended not to use this method in actual programming. Now I will give you an idea, which can do pagination processing in SQL query statements, and read a fixed number of records each time, as follows:
Start taking N records from the M record in the database table, and use the Top keyword: Note that if there is both top and order by in the Select statement, you will select from the sorted result set:
SELECT *
FROM (SELECT Top N *
FROM (SELECT Top (M + N - 1) * FROM Table Name Order by ID desc) t1 ) t2
Order by ID desc
If you use the above SQL statements to paginate, there will be fewer errors, and the most important thing is that you have higher efficiency.
Share: ASP instance tutorial: Form collection Note for Form collections: Because this ASP instance tutorial is about the code of the form, I will not take screenshots in order to save trouble! Everyone tests the execution results of the examples by themselves! A simple application of a Form collection This example demonstrates how a Form collection can retrieve values from a form. This form uses the POST method, which means that the message sent is invisible to the user and is for the sent message