How do I implement pagination in SQL for MS Access?

前端 未结 6 1471
自闭症患者
自闭症患者 2020-11-30 06:02

I\'m accessing a Microsoft Access 2002 database (MDB) using ASP.NET through the OdbcConnection class, which works quite well albeit very slowly.

My quest

6条回答
  •  清歌不尽
    2020-11-30 06:58

    If you wish to apply paging in MS Acces use this

    SELECT *
    FROM (
        SELECT Top 5 sub.ClientCode
        FROM (
            SELECT TOP 15 tblClient.ClientCode
            FROM tblClient
            ORDER BY tblClient.ClientCode
        ) sub
       ORDER BY sub.ClientCode DESC
    ) subOrdered
    ORDER BY subOrdered.ClientCode
    

    Where 15 is the StartPos + PageSize, and 5 is the PageSize.

    EDIT to comment:

    The error you are receiving, is because you are trying to reference a column name assign in the same level of the query, namely rownumber. If you were to change your query to:

    SELECT *
    FROM (
        SELECT ClientCode,
               (SELECT COUNT(c2.ClientCode)
                FROM tblClient AS c2
                WHERE c2.ClientCode <= c1.ClientCode) AS rownumber                
        FROM tblClient AS c1
    )
    WHERE rownumber BETWEEN 0 AND 15
    

    It should not give you an error, but i dont think that this is the paging result you want.

提交回复
热议问题