GetByIdAsync

A part of the IQSDataTable interface, this method provides a standardized way to retrieve a single record from a data source based on a unique identifier. It is designed to be flexible, allowing callers to specify which columns to return, and is implemented asynchronously to support efficient data access patterns.

Asynchronously retrieves a DataTable from the underlying data source for a given unique identifier, with optional control over the returned columns.

Data retrieved from this method is for read-only purposes. The returned DataTable should not be modified directly. If modifications for the returned row are necessary, consider using GetRowByIdAsync() or GetRowBySerialAsync() methods to retieve a IQSDataTableRow object that can be edited and then saved back to the data source.

Signature

public async Task<DataTable> GetByIdAsync(string Id, string TargetFields = "")

Parameters

NameTypeDescription
IdstringThe unique identifier of the record to retrieve. This value is forwarded to the command builder.
TargetFieldsstring (optional) A comma‑separated list of column names to include in the result set. When empty or omitted, all columns are returned.

Returns

A Task<DataTable> that represents the asynchronous operation. The DataTable contains the row matching the given Id, or an empty table if no match is found.

Example Usage

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

//Define the unique identifier for the record to retrieve
string recordId = "00000000-0000-0000-0000-000000000000";

// Retrieve full record
DataTable customer = await customersTable.GetByIdAsync(recordId);

// Retrieve only selected columns
DataTable limited = await customersTable.GetByIdAsync(recordId, "Name,Email,Phone");