ADO.NET Data

  • 3 minutes to read

The Data Source Configuration Wizard allows you to bind the PivotGridControl to an ADO.NET DataSet at design time. You can also bind the PivotGridControl to a DataSet in code. This topic shows how to do this.

Binding to a DataSet at Design Time

  1. Click the Data Source Wizard button placed on the PivotGridControl or use a corresponding command in a control's smart tag.

    WinPivot_DataSourceButton

  2. In the invoked Data Source Configuration Wizard, select ADO.NET Typed DataSet...

    DataSourceConfigurationWizard_SelectAdoNet

    ... and click the New Data Source button placed within the Data Sources area.

    DataSourceConfigurationWizard_SelectAdoNet_NewDataSource

  3. The following message will appear.

    DataSourceConfigurationWizard_RebuildWarning

    Click OK.

  4. In the invoked Data Source Configuration Wizard, you can establish a connection to the required database.

    DataSourceConfigurationWizard_MS_SelectDatabase

    To learn how to use the Data Source Configuration Wizard, see the following MSDN topic: Data Source Configuration Wizard.

    IMPORTANT

    After you created the data source, rebuild the solution.

  5. After creating a data source, click the Data Source Wizard button again.

    WinPivot_DataSourceButton

  6. In the invoked Data Source Configuration Wizard, select the created DataSet.

    DataSourceConfigurationWizard_AdoNet_ExistingDataSource

    Click Next.

  7. On the next page, select the required binding method.

    DataSourceConfigurationWizard_AdoNet_BindingMethod

    Select Direct Binding to Data Source and click Next.

  8. On the final page, you can specify the table from the created DataSet.

    DataSourceConfigurationWizard_AdoNet_SelectTable

    Select the required table and click Finish.

  9. The PivotGridControl will be bound to the created DataSet.

    WinPivot_BoundToDataSet

    You can now use the Retrieve Fiels command to retrieve the available data source fields. As an alternative, you can add specific fields manually using the PivotGrid Designer. To do this, use the Run Designer... command.

Binding to a DataSet in Code

The following code illustrates how to bind the PivotGridControl to the SalesPerson view of the Northwind database at runtime.

using System.Data;
using System.Data.OleDb;

            // ...
            // Create a connection object.
            OleDbConnection connection =
            new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\Data\nwind.mdb");
            // Create a data adapter.
            OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM SalesPerson", connection);

            // Create and fill a dataset.
            DataSet sourceDataSet = new DataSet();
            adapter.Fill(sourceDataSet, "SalesPerson");

            // Assign the data source to the PivotGridControl and create pivot grid fields for all data source fields.
            pivotGridControl1.DataSource = sourceDataSet.Tables["SalesPerson"];
            pivotGridControl1.RetrieveFields();