Back to Devexpress

SqlDataSource.Fill() Method

corelibraries-devexpress-dot-dataaccess-dot-sql-dot-sqldatasource-2a66ba74.md

latest7.8 KB
Original Source

SqlDataSource.Fill() Method

Validates and executes all valid queries available in the SqlDataSource.Queries collection.

Namespace : DevExpress.DataAccess.Sql

Assembly : DevExpress.DataAccess.v25.2.dll

NuGet Package : DevExpress.DataAccess

Declaration

csharp
public void Fill()
vb
Public Sub Fill

Remarks

If errors occur during data connection, a DatabaseConnectionException is thrown.

All queries are validated one by one. When validation errors occur, they are collected and returned by throwing an AggregateException. Use its InnerExceptions property to access a collection of QueryExecutionException objects (use each object’s InnerException property to access an actual ValidationException).

If the validation succeeds, all queries are executed one by one. If any errors occur during the execution of each query, these errors are collected and returned by throwing an AggregateException. Use its InnerExceptions property to access a collection of QueryExecutionException objects (use each object’s InnerException property to access an actual DevExpress.DataAccess.Native.Sql.SqlExecutionException ).

To validate and execute only specific queries, use a corresponding Fill method overload with the queriesToFill parameter.

Example

The following code sample creates a new SqlDataSource:

csharp
using DevExpress.DataAccess.ConnectionParameters;
using DevExpress.DataAccess.Sql;
using DevExpress.XtraReports.UI;
// ...
private static SqlDataSource CreateSQLDataSource()
{
    // Creates a data source. 
    SQLiteConnectionParameters connectionParameters = new SQLiteConnectionParameters("Data/nwind.db", "");
    SqlDataSource dataSource = new SqlDataSource(connectionParameters);

    // Creates a SELECT query.
    SelectQuery query = SelectQueryFluentBuilder
        .AddTable("Products")
        .SelectColumn("ProductName")
        .SelectColumn("UnitPrice")
        .Build("selectQuery");

    // Adds the query to the collection and returns the data source. 
    dataSource.Queries.Add(query);
    dataSource.Fill();
    return dataSource;
}
vb
Imports DevExpress.DataAccess.ConnectionParameters
Imports DevExpress.DataAccess.Sql
Imports DevExpress.XtraReports.UI
' ...
Private Shared Function CreateSQLDataSource() As SqlDataSource
    ' Creates a data source. 
    Dim connectionParameters As New SQLiteConnectionParameters("Data/nwind.db", "")
    Dim dataSource As New SqlDataSource(connectionParameters)

    ' Creates a SELECT query.
    Dim query As SelectQuery = SelectQueryFluentBuilder.AddTable("Products").SelectColumn("ProductName").SelectColumn("UnitPrice").Build("selectQuery")

    ' Adds the query to the collection and returns the data source. 
    dataSource.Queries.Add(query)
    dataSource.Fill()
    Return dataSource
End Function

The following code snippets (auto-collected from DevExpress Examples) contain references to the Fill() method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-grid-edit-the-sqldatasource-connection-and-query-at-runtime/CS/T292798/Form1.cs#L18

csharp
private void Form1_Load(object sender, EventArgs e) {
    sqlDataSource1.Fill();
}

winforms-grid-create-configure-sql-data-source/CS/dxSample/Form1.cs#L47

csharp
ds.Queries.Add(query);
ds.Fill();
return ds;

reporting-winforms-bind-mdb-with-select-query/CS/RuntimeBindingToMdbDatabase/Form1.cs#L41

csharp
ds.Queries.Add(query);
ds.Fill();
return ds;

winforms-query-builder/CS/Form1.cs#L31

csharp
sqlDataSource1.Fill();

winforms-dashboard-sql-data-source/CS/Dashboard_DashboardDataProviders/Form1.cs#L16

csharp
sqlDataSource.Queries.Add(CreateQuery("fluent"));
sqlDataSource.Fill();
dashboardDesigner1.Dashboard = CreateDashboard(sqlDataSource);

winforms-grid-edit-the-sqldatasource-connection-and-query-at-runtime/VB/T292798/Form1.vb#L16

vb
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
    sqlDataSource1.Fill()
End Sub

winforms-grid-create-configure-sql-data-source/VB/dxSample/Form1.vb#L55

vb
ds.Queries.Add(query)
ds.Fill()
Return ds

reporting-winforms-use-a-custom-function-in-query-expression/VB/SelectQueryWindowsFormsApplication/Form1.vb#L32

vb
' Fill the data source.
ds.Fill()

reporting-winforms-bind-mdb-with-select-query/VB/RuntimeBindingToMdbDatabase/Form1.vb#L32

vb
ds.Queries.Add(query)
ds.Fill()
Return ds

winforms-query-builder/VB/Form1.vb#L32

vb
gridView1.Columns.Clear()
sqlDataSource1.Fill()
gridControl1.DataSource = sqlDataSource1

See Also

SqlDataSource Class

SqlDataSource Members

DevExpress.DataAccess.Sql Namespace