[Reprint] Use row_number function paging in Asp.net

Source: Internet
Author: User
OnlineArticleThe top and other methods in sqlserver2000 are used for paging. In fact, the row_number () function paging after sqlserver2005 is the best method. The statement is simple and the idea is clear. It may be that vs2008 does not support the row_number function well, it cannot be automatically generated, so many people don't need it. Let's share the process of using the row_number function to implement paging.

A) First, create a query named querythreadcountbyforumid in dataadapter and return a value of scalar. The SQL statement is: Select count (*) as expr1 from rp_threads where (forumid = @ forumid)

B) create a query named getdatabyforumid in dataadapter. The SQL statement is select * from (select threadid, isvisible, lastupdatedate, Dateline, subject, forumid, row_number () over (order by Dateline) rownum from rp_threads where forumid = @ forumid) t where rownum> @ startrowindex and rownum <= @ startrowindex + @ maximumrows. Because the vs2008 designer does not support window function over, a warning is prompted, regardless of it. For over statements, vs2008 does not help generate dataset fields and parameters. Fortunately, the default getdata statement has already helped us generate fields. Although getdatabyforumid has one more rownum field than getdata, however, as long as the new query is not less than the field generated by getdata, many parts will be ignored. The following describes how to manually create parameters, select the getdatabyforumid method, modify the parameters attribute, and create three int32 attributes forumid, startrowindex, and maximumrows, enter @ forumid, @ startrowindex, and @ maximumrows for the corresponding parametername respectively.

C) use the objectdatasource data source on the interface. Set "typename" to the class name of dataadapter, "querythreadcountbyforumid" to "selectcountmethod", and "getdatabyforumid" to "selectparameters" to "forumid, the maximumrows and startrowindex generated by default can be deleted, because the pages are automatically filled with the two.

 

The article is reproduced from:Http://www.rupeng.com/forum/thread-11334-1-1-uid7.html 

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.