SqlDataSource.FillAsync(IEnumerable<IParameter>) Method
Populates the SqlDataSource in an asynchronous manner and passes external parameters to the data source.
Namespace: DevExpress.DataAccess.Sql
Assembly: DevExpress.DataAccess.v24.1.dll
NuGet Packages: DevExpress.DataAccess, DevExpress.Win.PivotGrid, DevExpress.Win.TreeMap
Declaration
Parameters
Name | Type | Description |
---|---|---|
sourceParameters | IEnumerable<IParameter> | External parameters passed to the data source. |
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.
All queries 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 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).
To validate and execute only specific queries, use a FillAsync method overload that accepts the queriesToFill parameter.
Example
The code sample below creates an SqlDataSource, binds the data source query’s OrderIDs parameter to the OrderIDsParameter report parameter, and populates the data source in an asynchronous manner.
using DevExpress.DataAccess.ConnectionParameters;
using DevExpress.DataAccess.Sql;
using DevExpress.XtraReports.Parameters;
using DevExpress.XtraReports.UI;
using System.Drawing;
// ...
SqlDataSource DataSource { get; set; }
// ...
public XtraReport CreateReportWithParameter()
{
XtraReport report = new XtraReport()
{
Bands = {
new DetailBand() {
Name = "detailBand",
Controls = {
new XRLabel() {
Name = "CategoryID",
BoundsF = new RectangleF(0,0,100,25),
ExpressionBindings = {
new ExpressionBinding("BeforePrint", "Text", "[CategoryID]")
}
},
new XRLabel() {
Name = "CategoryName",
BoundsF = new RectangleF(100,0,200,25),
ExpressionBindings = {
new ExpressionBinding("BeforePrint", "Text", "[CategoryName]")
}
}
}
}
},
};
report.Parameters.Add(new Parameter()
{
Name = "p_catID",
Type = typeof(int),
Value = 3
});
return report;
}
// ...
public void CreateSqlDataSourceWithParameter()
{
MsSqlConnectionParameters connectionParameters = new MsSqlConnectionParameters(
".", "NorthWind", null, null, MsSqlAuthorizationType.Windows);
var sqlDataSource = new SqlDataSource(connectionParameters) { Name = "Sql_Categories" };
var categoriesQuery = SelectQueryFluentBuilder
.AddTable("Categories")
.SelectAllColumnsFromTable()
.Build("Categories");
categoriesQuery.Name = "queryCategories";
QueryParameterInitialization(categoriesQuery);
sqlDataSource.Queries.Add(categoriesQuery);
sqlDataSource.RebuildResultSchema();
DataSource = sqlDataSource;
}
// ...
void QueryParameterInitialization(SelectQuery query)
{
QueryParameter parameter = new QueryParameter()
{
Name = "catID",
Type = typeof(DevExpress.DataAccess.Expression),
Value = new DevExpress.DataAccess.Expression("?p_catID", typeof(System.Int32))
};
query.Parameters.Add(parameter);
query.FilterString = "CategoryID = ?catID";
}
// ...
void AssignDataSourceToReport()
{
XtraReport report = CreateReportWithParameter();
report.DataSource = DataSource;
report.DataMember = "queryCategories";
}
// ...
async void FillDataSourcAsyncWithParameters(XtraReport report)
{
await DataSource.FillAsync(report.Parameters);
}
// ...
async void FillDataSourcAsyncQueriesWithParameters(XtraReport report)
{
await DataSource.FillAsync(report.Parameters, new string[] { "queryCategories" });
}