windowsforms-115499-controls-and-libraries-pivot-grid-binding-to-data-data-source-configuration-wizard-adonet-data.md
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.
Click the Data Source Wizard button placed on the PivotGridControl or use a corresponding command in a control’s smart tag.
In the invoked Data Source Configuration Wizard, select ADO.NET Typed DataSet …
The following message will appear.
In the invoked Data Source Configuration Wizard, you can establish a connection to the required database.
After creating a data source, click the Data Source Wizard button again.
In the invoked Data Source Configuration Wizard, select the created DataSet.
On the next page, select the required binding method.
On the final page, you can specify the table from the created DataSet.
The PivotGridControl will be bound to the created DataSet.
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();
Imports System.Data
Imports System.Data.OleDb
' ...
' Create a connection object.
Private connection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\Data\nwind.mdb")
' Create a data adapter.
Private adapter As New OleDbDataAdapter("SELECT * FROM SalesPerson", connection)
' Create and fill a dataset.
Private sourceDataSet As 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()