|
Paged Record Using GetRows Method |
| | | | Submitted on: 10/3/2002 7:33:02 AM
By: Muhannad Yousef
Level: Advanced User Rating: Unrated Compatibility:VB 6.0
Users have accessed this article 466 times. | (About the author) |
| | Paging through Records using a GetRows and PageSize,PageCount,AbsolutePage | | | Terms of Agreement:
By using this article, you agree to the following terms...
1) You may use
this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
2) You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
3) You may link to this article from another website, but ONLY if it is not wrapped in a frame.
4) You will abide by any additional copyright restrictions which the author may have placed in the article or article's description. | As an ASP developer, I am constantly looking for new source code examples that will help make my job easier. Of course, using someone else's examples is far simpler than enduring the pain of the development process.
One of the examples I have seen on various sites involves paging through recordsets on a web page N records at a time. Most developers want to do this rather than present the entire recordset on a single page. First, this has the advantage of making faster page loads for site visitors, and secondly it makes for nicer pages.
All of the examples I have seen use client-side cursors to move to an absolute page in the recordset. While this works quite nicely, there is one disadvantage that developers don't consider. In most cases, the server where the database resides is separate from the web server. Whenever a request is made to the database server, it returns the entire recordset to the web server, which then uses the client-side cursor to only select the group of records requested for the given page. This does not seem like a problem until you consider what happens when you are working with large databases and multiple concurrent users. If you are only requesting 40 records at a time from a 100,000 record database table, and you have 5 people make the same request, you are now sending 500,000 records to the web server for only 200 records of output to the client. This can be an enormous problem!
i solved this problem by using both GetRows method and PageSize,PageCount,AbsolutePage, here is the search function,
----------------------------------------------------------------------------------------------------
Function Search (KW as string,m__CurPage as long,m__RPerPage as long)
con.Open Connection_string
Q = "SELECT itmID,ItmName,ItmUrl,ItmAbout From Information where ItmName like '%" & KW & "'%"
rs.CursorLocation = adUseClient
rs.Open Q, con, adOpenDynamic, adLockOptimistic
rs.PageSize = m__RPerPage
Total_Pages = rs.PageCount
rs.AbsolutePage = m__CurPage
m_RecordFound = rs.RecordCount
If Not rs.EOF Then
SearchArr = rs.GetRows(m__RPerPage, rs.Bookmark)
Search = SearchArr
End If
con.Close
End Function
----------------------------------------------------------------------------------------------------
with this code there is no load on the web server, all the loads moves to the Database.
the function here take 3 paremeter, the first one is the search Keyword and the second one is the page number,and the 3rd one is the number of record per page, the function return a two dimensional array contains the number of record depend on the 3rd parameter.
| | | Report Bad Submission | | | Your Vote! |
See Voting Log | | Other User Comments | 10/3/2002 12:15:05 PM: Hi,
how is there no load on the web
server?
All the data is loaded into a
client side cursor and then the paging
is done on the server.
| | Add Your Feedback! | Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.
NOTICE: The author of this article has been kind enough to share it with you. If you have a criticism, please state it politely or it will be deleted.
For feedback not related to this particular article, please click here. | | |