Skip to main content
A newer version of this page is available. .

SqlDataSource.FillAsync(IEnumerable<IParameter>, String[], CancellationToken) Method

Populates the SqlDataSource in an asynchronous manner, passes external parameters to the data source, and uses the cancellationToken parameter to send the cancellation signal. You can specify which queries to execute in order to populate the data source.

Namespace: DevExpress.DataAccess.Sql

Assembly: DevExpress.DataAccess.v20.2.dll

NuGet Packages: DevExpress.DataAccess, DevExpress.WindowsDesktop.DataAccess

Declaration

public Task FillAsync(
    IEnumerable<IParameter> sourceParameters,
    string[] queriesToFill,
    CancellationToken cancellationToken
)

Parameters

Name Type Description
sourceParameters IEnumerable<IParameter>

External parameters passed to the data source.

queriesToFill String[]

Queries to execute in order to populate the data source.

cancellationToken CancellationToken

A cancellation token that the task observes.

Returns

Type Description
Task

A task that populates the data source.

Remarks

Use this method to populate an SQL data source in an individual task asynchronously. Unlike the Fill() method call, FillAsync does not lock other actions performed concurrently. For instance, the user interface remains operational while the data source is populated.

Call the FillAsync method with the await operator.

The sourceParameters parameter passes a collection of external parameters to the data source. For instance, you can pass report parameters from a reporting application and use report parameter values to filter data.

The queriesToFill array specifies the names of the queries to execute in order to populate the data source.

The cancellationToken parameter provides a way to send the cancellation signal to the task. The task monitors the token and stops when it receives the signal. Create a CancellationTokenSource class instance and pass its Token property to the FillAsync method call. Call the CancellationTokenSource.Cancel method to stop the task.

All queries listed in the queriesToFill parameter are validated one by one. If any validation errors occur, an AggregateException is thrown with these errors. Use the exception’s InnerExceptions property to access a collection of QueryExecutionException objects (use their InnerException property to access an actual ValidationException).

If the validation succeeds, all listed queries are executed one by one. If any errors occur, an AggregateException is thrown with these errors. Use the exception’s InnerExceptions property to access a collection of QueryExecutionException objects (use their InnerException property to access an actual DevExpress.DataAccess.Native.Sql.SqlExecutionException).

Example

The code sample below creates an SqlDataSource, binds the data source query’s OrderIDs parameter to the OrderIDsParameter report parameter, and populates the queryInvoices data member in an asynchronous manner. A CancellationTokenSource class instance is used to allow users to interrupt the data source fill process if it takes too long.

using System.Threading;
using System.Threading.Tasks;
using DevExpress.DataAccess;
using DevExpress.DataAccess.Sql;
using DevExpress.DataAccess.ConnectionParameters;
// ...
// Use the cancellationTokenSource to allow users to stop populating the data source.
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
// ...
// The cancelButton_Click event handler uses cancellationTokenSource to stop populating the data source.
private void cancelButton_Click(object sender, EventArgs e) {
    cancellationTokenSource.Cancel();
}
// ...
// Create and configure an SQL data source.
Access97ConnectionParameters connectionParameters = new Access97ConnectionParameters(".\\Data\\nwind.mdb", "", "");
DevExpress.DataAccess.Sql.SqlDataSource dataSource = new DevExpress.DataAccess.Sql.SqlDataSource(connectionParameters);
// Create the "queryInvoices" query that serves as a data member.
CustomSqlQuery queryInvoices = new CustomSqlQuery();
queryInvoices.Name = "queryInvoices";
queryInvoices.Sql = "SELECT OrderID, OrderDate, ShipName, sum(ExtendedPrice) as Total FROM Invoices WHERE OrderID in (?OrderIDs) GROUP BY OrderID,OrderDate,ShipName";
queryInvoices.Parameters.Add(new QueryParameter("OrderIDs", typeof(System.Int32), "?OrderIDsParameter"));
dataSource.Queries.Add(queryInvoices);
report.DataSource = dataSource;
report.DataMember = "queryInvoices";
// Populate the data source.
await dataSource.FillAsync(report.Parameters, new string[] { "queryInvoices" }, cancellationTokenSource.Token);
See Also