Skip to content

Chained CRUD - Terminal Methods

Terminal methods execute the actual database operations. After execution, the builder state is automatically reset (ResetBuilder). For architecture details, see Chained CRUD Overview.


Field - Set Field Value

Used with RowCreate and RowUpdate to set insert/update field values.

Syntax

vb
Function Field(ByVal FieldName As String, ByVal Value As Variant) As cDataBase

Example

vb
' Set field values for insert
db.Table("users").Field("name", "Zhang San").Field("age", 25).RowCreate

' Set field values for update
db.Table("users").Where("id=?", 1).Field("name", "Zhang San Updated").Field("age", 26).RowUpdate

RowCreate - Create Row

Syntax

vb
Function RowCreate() As cDataBase

Usage Patterns

vb
' Pattern 1: Chained Field (recommended, one-line insert)
With db.Table("users")
    .Field "name", "Zhang San"
    .Field "age", 25
    .Field "email", "zhang@example.com"
    .RowCreate
End With

' Pattern 2: Traditional Rs editing (suitable for per-field judgment scenarios)
With db.Table("users").RowCreate
    .Rs!name = "Zhang San"
    .Rs!age = 25
    .Rs.Update
End With

' Get auto-increment ID after insert
With db.Table("users")
    .Field "name", "Li Si"
    .RowCreate
    Debug.Print "New ID: " & db.LastInsertId
End With

RowRead - Query Rows

Syntax

vb
Function RowRead() As cDataBase

Query results are stored in db.Rs (Recordset), accessible via db.Rs!FieldName.

Example

vb
' Simple query
If db.Table("users").Where("id=?", 1).RowRead Then
    Debug.Print db.Rs!name
End If

' Complex chained query
db.Table("users") _
    .Columns("id,name,age") _
    .Where("age>?", 18) _
    .WhereIn("dept", "IT,HR") _
    .OrderByDesc("age") _
    .Limit(10) _
    .RowRead

' Iterate results
If db.Table("users").Where("status=?", "active").RowRead Then
    Do Until db.Rs.EOF
        Debug.Print db.Rs!name & " - " & db.Rs!age
        db.Rs.MoveNext
    Loop
End If

RowUpdate - Update Row

Syntax

vb
Function RowUpdate() As cDataBase

Usage Patterns

vb
' Pattern 1: Chained Field (recommended, one-line update)
With db.Table("users").Where("id=?", 1)
    .Field "name", "Zhang San Updated"
    .Field "age", 26
    .RowUpdate
End With

' Pattern 2: Traditional Rs editing
With db.Table("users").Where("id=?", 1).RowUpdate
    .Rs!name = "Zhang San Updated"
    .Rs.Update
End With

' Batch update (with WhereIn)
With db.Table("users").WhereIn("id", 1, 2, 3)
    .Field "status", "archived"
    .RowUpdate
End With

Note: RowUpdate requires a Where condition to prevent accidental full-table updates.


RowDelete - Delete Row

Syntax

vb
Function RowDelete() As cDataBase

Example

vb
' Delete by ID
db.Table("users").Where("id=?", 1).RowDelete

' Batch delete
db.Table("users").WhereIn("id", 5, 8, 13).RowDelete

' Conditional delete
db.Table("logs").Where("created_at<'2025-01-01'").RowDelete

' Combined condition delete
db.Table("users") _
    .Where("status=?", "expired") _
    .WhereNull("email") _
    .RowDelete

Note: RowDelete requires a Where condition to prevent accidental full-table deletion.


Last Updated: 2026-06-26

VB6 and LOGO copyright of Microsoft Corporation