GetScalarValueByIdAsync
Part of the IQSDataTable interface, this method retrieves a single scalar value from the data source. It directly queries a specific column (TargetField) for the record identified by Id.
Asynchronously returns the value of the requested field as object?, or null if no matching record exists. The caller is expected to cast the result to the appropriate type (e.g., decimal, string).
Signature
public async Task<object?> GetScalarValueByIdAsync(string Id, string TargetField)Parameters
| Name | Type | Description |
|---|---|---|
Id | string | The unique identifier of the record to query. |
TargetField | string | The name of the column whose value should be returned. This field is inserted directly into the generated SQL query. |
Returns
A Task<object?> representing the asynchronous operation. The result is the value of the TargetField column for the first row where [Id] matches the supplied Id. If no such row is found, null is returned.
Note: Because the return type is object?, you must cast the result to the expected data type (e.g., (decimal)value or .ToString()).
Example Usage
// Define the data table
IQSDataTable customersTable = QSAppContext.Tables["Customers"];
//Define the unique identifier for the record to retrieve the scalar value from
string recordId = "00000000-0000-0000-0000-000000000000";
// Retrieve a string scalar
string? name = (string?)await customersTable.GetScalarValueByIdAsync(recordId, "Name");
// Retrieve a numeric scalar
decimal? totalSales = (decimal?)await customersTable.GetScalarValueByIdAsync(recordId, "TotalSales");
if (totalSales.HasValue)
{
//Do something with totalSales.Value
}