GetScalarValueBySerialAsync
Part of the IQSDataTable interface, this method returns a single scalar value from the data source, looking up the record by its Serial number instead of an Id.
Asynchronously returns the value of the requested TargetField for the record with the specified Serial. If no matching row is found, null is returned. The caller must cast the result to the expected type (e.g., decimal, string).
Signature
public async Task<object?> GetScalarValueBySerialAsync(decimal Serial, string TargetField)Parameters
| Name | Type | Description |
|---|---|---|
Serial | decimal | The unique serial number of the record to query. |
TargetField | string | The name of the column whose value should be returned. It is placed 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 row where [Serial] equals the provided Serial. If no such row exists, the method returns null.
Note: Because the return type is object?, you must cast it to the appropriate data type, for example (decimal)value or .ToString().
Example Usage
// Define the data table
IQSDataTable productsTable = QSAppContext.Tables["Products"];
// Serial number of the product
decimal productSerial = 1001;
// Retrieve a string scalar
string? productName = (string?)await productsTable.GetScalarValueBySerialAsync(productSerial, "ProductName");
// Retrieve a numeric scalar
decimal? unitPrice = (decimal?)await productsTable.GetScalarValueBySerialAsync(productSerial, "UnitPrice");
if (unitPrice.HasValue)
{
//Do something with unitPrice.Value
}