ExecuteSelectStoredProcedureToDataTableAsync
Part of the QSAppContext object. Executes a stored procedure that returns a result set and delivers the output as a standard DataTable. This is the lower‑level counterpart of ExecuteSelectStoredProcedureToDictionaryAsync and is ideal when you need full column metadata or plan to bind the results directly to grid controls.
The stored procedure is specified via a SqlCommandDto with CommandType set to CommandType.StoredProcedure. The CommandText must be the stored procedure name, and parameters are supplied through the Parameters collection.
Signature
public async Task<DataTable> ExecuteSelectStoredProcedureToDataTableAsync(SqlCommandDto command)Parameters
| Name | Type | Description |
|---|---|---|
command | SqlCommandDto | The command object describing the stored procedure call. Must have CommandType = CommandType.StoredProcedure and CommandText set to the procedure name. Any required parameters are added via command.Parameters.Add* methods. |
Returns
A Task<DataTable> representing the asynchronous operation. The DataTable contains all rows and columns returned by the stored procedure. If the procedure produces no result set, an empty DataTable is returned (never null).
Example Usage
// Build a command that calls a stored procedure
SqlCommandDto cmd = new SqlCommandDto
{
CommandText = "GetActiveCustomersByMinSales",
CommandType = CommandType.StoredProcedure
};
// Add parameters using the typed helpers
cmd.Parameters.AddDecimal("MinSales", 10000M, SqlDbType.Decimal);
cmd.Parameters.AddString("Status", "Active", size: 50, isNullable: false);
// Execute the stored procedure
DataTable dt = await QSAppContext.ExecuteSelectStoredProcedureToDataTableAsync(cmd);
foreach (DataRow row in dt.Rows)
{
Console.WriteLine($"{row["Name"]} – {row["TotalSales"]}");
}