Database component Hxj.data (20) (paging)

Source: Internet
Author: User

The Liezi in the previous sections of the page have already appeared and are now being explained in detail.

There are three ways to achieve this:

1, top (int TopCount) method

In SQL Server and MSAccess in fact is top, in Oracle through ROWNUM implementation.

2, from (int startIndex, int endindex)

The number of records from the startindex bar to the Endindex bar.

3, Page (int pageSize, int pageIndex)

PageSize per page, page pageindex

These three methods are illustrated in turn below.

Top method:

DbSession.Default.From<Products>()
.Top(10)
.ToList();

The query is queried for the first 10 records in the Products table, and the resulting SQL statement is as follows: (How to output a view component-generated SQL)

Text:

SELECT Top * FROM [products]

From method:

DbSession.Default.From<Products>()
.From(3, 8)
.ToList();

Find data from Articles 3rd through 8th (including 3rd and 8th), and the resulting SQL statement is as follows:

Text:

SELECT * FROM
( SELECT TOP 6 * FROM
( SELECT TOP 8 * FROM [Products] ORDER BY [Products]. [ProductID] ASC)
AS tempIntable ORDER BY [ProductID] DESC)
AS tempOuttable ORDER BY [ProductID] ASC 

Page Method:

DbSession.Default.From<Products>()
.Page(10, 2)
.ToList();

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.