DeleteRecordAsync

Part of the IQSDataTable interface, this method deletes a single record using an IQSDataTableRow object. It automatically extracts the row’s Id field to identify which record to remove.

This method provides a convenient way to delete a record when you already have an IQSDataTableRow instance, such as one retrieved from a previous select operation. By passing the entire row object, the method can internally access the necessary identifier to construct the delete statement.

the (BatchId) is used to associate the targeted row, which is useful for tracking the deleted row and used later when calling SaveBatchAsync(BatchId) or SaveBatchOnlyAsync(BatchId) to apply the corresponding deletes to the data source.

The delete operation can be executed immediately or added to a batch queue via a BatchId. The return value indicates how many rows were deleted (immediate mode) or confirms the query was queued.

Signature

public async Task<int> DeleteRecordAsync(IQSDataTableRow record, Guid BatchId, bool ImmediateAction = false)

Parameters

NameTypeDescription
recordIQSDataTableRow The row object representing the record to delete. Its Id field is used to construct the delete statement.
BatchIdGuid A unique identifier for the batch. When ImmediateAction is false, the delete query is added to the execution queue for this batch.
ImmediateActionbool (optional, default false) If true the delete is executed immediately; if false the query is queued.

Note

This method is a convenient wrapper around the more specific delete methods like DeleteRecordByIdAsync or DeleteRecordBySerialAsync. It abstracts away the need to manually extract the record’s identifier, allowing you to simply pass the row object.

The record can also be deleted directly from the ISQDataTableRow object by calling its DeleteAsync(ImmediateAction) method. The sample is shown in the Example Usage section below.

Returns

A Task<int> representing the asynchronous operation.

  • Immediate mode: the number of rows deleted (typically 1 on success, 0 if the ID didn’t match).
  • Queued mode: returns 1 indicating the query was successfully added to the batch queue.

Example Usage

// Define the data table
IQSDataTable customersTable = QSAppContext.Tables["Customers"];

// Create or obtain a row object (e.g., from a previous query)
string recordId = "00000000-0000-0000-0000-000000000000";
Guid batchId = Guid.NewGuid();
IQSDataTableRow rowToDelete = await customersTable.GetRowByIdAsync(recordId, batchId);

// Queue the delete (default)
int queuedResult = await customersTable.DeleteRecordAsync(rowToDelete, batchId);

// Delete immediately
int deletedRows = await customersTable.DeleteRecordAsync(rowToDelete, batchId, true);

Console.WriteLine($"Queued: {queuedResult}, Deleted: {deletedRows}");

// NOTE: The record can also be deleted directly from the ISQDataTableRow object:
// Queue the delete
int queuedResult = await rowToDelete.DeleteAsync();
// Delete immediately
int deletedRows = await rowToDelete.DeleteAsync(true);
// No batchId is needed when deleting from the row object since it is already associated with the targeted record.
Console.WriteLine($"Queued: {queuedResult}, Deleted: {deletedRows}");