Skip to content

Chained CRUD - Limit & Pagination

Limit and pagination methods control the number and offset of query results. For architecture details, see Chained CRUD Overview.


Limit - Limit Return Count

Simple truncation for non-pagination scenarios, suitable for "get latest N records" etc.

Syntax

vb
Function Limit(ByVal N As Long) As cDataBase

Database Adaptation

DatabaseGenerated SQL
MySQLLIMIT N
SQL ServerOFFSET 0 ROWS FETCH NEXT N ROWS ONLY
AccessAutomatically converts to ADO pagination mechanism

Example

vb
' Get latest 10 records
db.Table("logs").OrderByDesc("id").Limit(10).RowRead

' Get top 5 active users
db.Table("users").Where("status=?", "active").OrderBy("name").Limit(5).RowRead

Offset - Offset

Used with Limit to skip the first N records.

Syntax

vb
Function Offset(ByVal N As Long) As cDataBase

Database Adaptation

DatabaseGenerated SQL
MySQLLIMIT Offset, Limit
SQL ServerOFFSET N ROWS FETCH NEXT M ROWS ONLY

Example

vb
' Skip first 20, take 10 (page 3, 10 per page)
db.Table("users").OrderBy("id").Limit(10).Offset(20).RowRead

' Rankings: skip top 100, take 50
db.Table("scores").OrderByDesc("score").Limit(50).Offset(100).RowRead

Page - ADO Pagination

Based on ADO native pagination properties (PageSize + AbsolutePage), works for all database types.

Syntax

vb
Function Page(Optional Num As Long = 1, Optional Limit As Long = 10) As cDataBase

Parameter Description

ParameterTypeDescription
NumLongPage number (optional, default 1)
LimitLongRecords per page (optional, default 10)

Example

vb
' Page 2, 20 per page
db.Table("users").OrderBy("id").Page(2, 20).RowRead

' Chained pagination query
db.Table("users") _
    .Where("status=?", "active") _
    .OrderByDesc("created_at") _
    .Page(1, 10) _
    .RowRead

' Comparison with traditional Sql approach
' Traditional: db.Sql("SELECT * FROM users").Page(1, 10).Fetch
' Chained: db.Table("users").Page(1, 10).RowRead  (more concise)

Note: Do not use Page and Limit/Offset simultaneously as their functionality overlaps. Page is suitable for standard pagination, Limit/Offset for flexible truncation.


Last Updated: 2026-06-26

VB6 and LOGO copyright of Microsoft Corporation