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 cDataBaseDatabase Adaptation
| Database | Generated SQL |
|---|---|
| MySQL | LIMIT N |
| SQL Server | OFFSET 0 ROWS FETCH NEXT N ROWS ONLY |
| Access | Automatically 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).RowReadOffset - Offset
Used with Limit to skip the first N records.
Syntax
vb
Function Offset(ByVal N As Long) As cDataBaseDatabase Adaptation
| Database | Generated SQL |
|---|---|
| MySQL | LIMIT Offset, Limit |
| SQL Server | OFFSET 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).RowReadPage - 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 cDataBaseParameter Description
| Parameter | Type | Description |
|---|---|---|
Num | Long | Page number (optional, default 1) |
Limit | Long | Records 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
PageandLimit/Offsetsimultaneously as their functionality overlaps.Pageis suitable for standard pagination,Limit/Offsetfor flexible truncation.
Last Updated: 2026-06-26