Database

CRUD Operations

Methods for reading, creating, updating, and deleting database records, and for executing arbitrary SQL commands.

Methods for reading, creating, updating, and deleting database records, and for executing arbitrary SQL commands.

Read, Create, Update, and Delete are intent-setting properties that configure the operation type. After calling one, chain the query source (WithSQLCommand, WithStoredProcedure, or WithTableName) and then execute with Execute, IntoDataTable, or IntoGrid. Execute runs the command and returns an affected row count. The SQL commands for each operation are configured with WithReadAs, WithCreateAs, WithUpdateAs, and WithDeleteAs.

TIP

Read, Create, Update, and Delete are properties that set the operation mode. They do not execute immediately - execution happens when you call Execute(), IntoDataTable(), or IntoGrid() at the end of the chain.

Examples

GPAL Fluent: High-level fluent C# API

//Parameters are added with WithParameter in the order they appear in the SQL command. For named parameters, use WithParameterName to set the name before adding each value.

// Read records into a grid var grid = GPAL.Grid.ToGPALObject(); GPAL.Database .WithConnectionString(connStr) .WithSQLCommand("SELECT Name, Email FROM Customers WHERE Active = 1") .Read .IntoGrid(out grid); // Execute an update int rowsAffected; GPAL.Database .WithConnectionString(connStr) .WithSQLCommand("UPDATE Customers SET Status = @status WHERE Id = @id") .WithParameter("active") .WithParameter("42") .Update .Execute(out rowsAffected);