ASP Programming Introduction (20): Ado Component Subject

xiaoxiao2021-03-06  38

It should be, learn how to insert records, how to display records, so simple and complete article systems, news systems and message systems are not problematic. Then the following question is: As the information content is increased, all information is not rationally via a page separately. Therefore, the solution is to use paging technology. 1. Rs.RecordCount is clear that RecordCount is used to display a lot of records in the database table, or how many rows can be in the table. It is often used in paging to have a total of N-article and other total information display. 2, rs.pagesizers.pageSize is also a page size, which means an ASP page can display the number of records. The value is your own definition, such as the information you often showing the N articles. 3, RS.AbsolutePage and RS.PageCount say paging, must not mention RS.AbsolutePage. The most important role of the AbsolutePage property of the record set is to determine the current display. Its value is based, specified rspagesize, then rs.pagecount's information value is RS.Recordcount and rs.pageSize completion results. For example: Total information records RS.Recordcount a total of 20, and the number of questions per page is set to 5, then the number of pages rs.pagecount is 20/5 = 4 pages, and RS.AbsolutePage can only be Page 1, Page 2 ... Page 4. Speaking of now, get a specific program to debug it. Continue to modify Showit.asp as follows:

<% set = server.createObject ("adoDb.recordset") SQL = "SELECT * from cnarticle order by cn_id desc" rs.open SQL, CONN, 1, 1%> <% Page = Request.QueryString ("page") 'page value is accepted rs.pagesize = 2' per page Display number rs.abs.absolutepage = Page 'Display current page is equal to receiving pages%> <% For i = 1 to rs.pageSize 'Use the for next loop to read the current page record IF ife.eof kilite ("
article content:" & RS ("cn_content" )) rs.MovenextNext%> <% rs.close set rs = nothingconn.close set conn = Nothing%>

Here, your debugging is that the records in the database are more than 4, so that the test effect is obvious; the test method is to add after Showit.asp? Page = 1 or? Page = 2 Contact Observation Weight display Effect . In fact, it is said that the content of the database is

<% For i = 1 to rs.pageSize if xi rs.eof kilite ("
article content is:" & rs ("cn_content") rs.movenextNext%>

The role, but imagined: the program should only display 2 information (all unchanged 2 information). But why add? Page = 1 and? Page = 2 Display different results? ... that is definitely the role of rs.absolutepage. This is clear, I believe that the overall architecture of the paging is a bit eyebrow.

<% set = server.createObject ("adoDb.recordset") SQL = "SELECT * from CNArticle" rsopen sql, conn, 1, 1% > <% filepath = request.servervariables ("path_info")%> <% page = request.queryString ("page") 'page value is accepted rs.pagesize = 2' per page display record number if not iSempty (PAGE) If Page has initialized ... if not isnumeric (PAGE) THEN 'Judging whether the page value is a number Page = 1 else Page = CINT (PAGE)' Receive Page and the digital assignment to the PAGE Variable END IF Page> rs.pagecount then 'If the received page is greater than the total number of pages rs.absolute, = rs.pagecount' Set the current display equal to the last page Elseif Page <= 0 THEN 'If the PAGE is less than or equal to 0 rs.absolutePage = 1' settings Current display Page is equal to the first page else aabsolutepage = page 'If it is greater than zero, display the current page is equal to the received page end ifelsers.absolutepage = 1END ifpage = rs.absolutepage%> <% for i = 1 to rs.pageSize' Using for NEXT loop sequentially reads the current page Record if ife.eof kilite ("Article title is:" & RS ("cn_title")) response.write ("
Author is:" & RS ("cn_author")) Response.write ("
):" & RS ("cn_time") Response.write ("
article content is:" & rs ("cn_content")) Respons E.Write ("


") rs.movenextNext%>
<% IF .Pagecount <> 1 and ..> <% IF Page> 1 THEN%> [

Page -1%> "> Previous ] [? Page = <% = rs.pagecount%>> Last page ] <% else%> [Next] [Last] <% end if%> <% else%> [Home] [Previous] [ Next Page ] [< A href = "<% = filepath%>? Page = <% = rs.pagecount%>> Last page ] <% end if%> <% else%> [Home] [Previous] [Next] [Last] <% End IF%> [Page: < % = Page%> <% = rs.record%> =% = r.recordcount% >> <% = rs.pageSize% > Page / Page] Go to page <% rs.close set = NothingConn.close set conn = NOTHING> Effect page See:

http://www.cnbruce.com/database/

Long paging code, it is really not easy, and the platform is quoted to modify it. Finally, you can make a function, it is convenient next time.

<% Function pagination (pagecount, pagesize, page, resultcount) Dim query, a, x, temp action = "http: //" & Request.ServerVariables ( "HTTP_HOST") & Request.ServerVariables ( "SCRIPT_NAME") query = Split (Request.servervariables ("Query_String"), "&") for Each X in Query A = Split (x, "=") IF STRComp (A (0), "Page", vbtextcompare) <> 0 THEN TEMP = Temp & A (0) & "=" & a (1) & "&" end if next response.write (" ") IF Page <= 1 Then Response.write (" [Home] [Previous] ") Else Response.write (" [ Home ]") Response.Write ("[ Previous ]") END IF IF Page> = PageCount Ten Response.write ("[Next] [Last]") Else Response.write ("[ Next page ] ") Response.write ("[

/ font> / "& pagecount) Response.write ("] "" & resultcount & "条 " & pagesize & " bar / page]") Response.write ("Go to "&" If you want to reference, you can: <% CALL PAGINATION. Rs.PageCount, Rs.PageSize, Page, Rs.RecordCount)%>


New Post(0)