For the phenomenon of negative numbers during the recordset paging, I believe that many people have encountered this problem, and sometimes Baidu and Google are not puzzled. Now I will summarize it.
A negative number is mainly related to the type of cursor. (For example, it is convenient, assuming that there is already a file of the conn.asp link database and it has been include.) Now an example is as follows:
SQL = SELECT * From Table WHERE Conditions Order by ID DESC 'here can be rewritten according to your needs
Set rs = const.execute (sql) '=== Note this sentence ===
RS.PAGESIZE = 10 '=== Set the number of records per page is 10 ===
Page = request.querystring (page)
If page = then page = 1
If not isnumeric (page) then page = 1
Page = ClNG (Page)
If page <1 the page = 1
If page> RS.PageCount that = 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 page link
According to the above code, the recordset object is directly by the code: set rs = conn.execute (SQL). After using this sentence, the default campaign of the recordset object is 0, that is, the cursor can only roll forward, and the type of locking is 0, indicating that only reading only reads only, indicating only reading only read, indicating only reading only read, indicating that only reading only reads only, indicating only reading only read, indicating that only reading only reads only, indicating only reading only read, indicating that only reading only reads only, indicating only reading only read, indicating only reading only read, indicating that only reading only reads only, indicating only reading only read, indicating that only reading only reads only, indicating only reading only read, indicating only reading only, indicating that only reading is read only. Lock, you cannot update the recordset object.
Therefore, if a negative number appears during paging, check whether the recordset object is written as the above form, and it should be written:
Set rs = server.createObject (Adodb.oldSet)
RS.Oopen SQL, CONN, 1,3
The above indicates that the cursor is 1, which can move forward and backward; the lock type is 3, which can be updated in batches in batches.
According to the above method, there will be no problem, but for insurance, the principle of the recionset paging is based on the number of records after reading all the records, so let the campaign roll around first, add the following after the level RS.PAGESIZE = 10, add the following below Two sentences:
RS.MOVELAST 'Cursor move to the end
RS.Movefirst 'Cursor move to the top
The pagination principle of the recordset is known to first read the records in the entire database before obtaining the value of the RS.RecordCount. This paging method is relatively simple, but there is a fatal disadvantage. When there are many records in the database records, according to the principle of paging, this will occupy high system resources, which is very wasteful. It is recommended not to use it in actual programming. method. Now give you a idea that you can do pagination in the SQL query statement. Each read a fixed record number is as follows:
Start from the Mist of Article M.
Select*
From (Selecttopn*
From (SELECTTOP (M+N-1)*from table name OrderByidDesc) T1) T2
OrderByidDesc
With the above SQL statements, the errors are relatively small, and the most important thing is that the efficiency is relatively high.