Step 1 of 4: Create a Data Source for Chart

In this step you will create a data source that you can later bind the chart to using the Chart Properties designer. Create a .NET project, and complete the following steps:

Add a new data source

1.   In the project toolbar, from the Data menu select Add New Data Source. The Data Source Configuration Wizard dialog box appears.

2.   Select Database and then click Next.

3.   Click New Connection.

4.   In the Choose Data Source dialog box, select Microsoft Access Database File and click Continue.

5.   In the Add Connection dialog box, click Browse.

6.   In the Select Microsoft Access Database File dialog box, locate the Nwind.mdb (located by default in C:\Program Files\ComponentOne\Studio for Winforms \Common), click Open, and then click OK.

7.   Click the Next button to continue. A dialog box will appear asking if you would like to add the data file to your project and modify the connection string. Since it is not necessary to copy the database to your project, click No.

8.   Verify the Yes, save the connection as check box is checked and click Next to continue.

The connection string is saved as NwindConnectionString.

9.   Expand the Tables node and select the Categories and Products objects.

10.  Click Finish.

NwindDataSet.xsd is added to your project.

Add an OleDbDataAdapter

11.  From the Toolbox, double-click the OleDbDataAdapter component.

Note: In Visual Studio 2005, right-click the Toolbox, and then click Choose Items. On the .NET Framework Components tab in the dialog box, select OleDbDataAdapter.

The OleDbDataAdapter appears in the component tray and the Data Adapter Configuration Wizard appears.

12.  In the Data Adapter Configuration Wizard, choose the connection you wish to use for the data adapter from the drop-down listbox (in this case, C:\Program Files\ComponentOne\Studio for Winforms \Common\Nwind.mdb\Nwind.mdb) and then click Next.

13.  The Use SQL Statements is selected by default, click Next.

14.  Copy and paste the following SQL statement in the textbox of the Data Adapter Configuration Wizard:

SELECT CategoryID, ProductName, UnitPrice, UnitsInStock, ReorderLevel FROM Products ORDER BY UnitPrice DESC

15.  Click Next and then click Yes to add primary key columns to your query.

16.  Click Finish.

Notice that the OleDbConnection1 component is automatically inserted in the component tray.

Generate a DataSet

Generate a DataSet that is related to OleDbDataAdapter1 by completing the following steps:

17.  Select OleDbDataAdapter1 and click on its smart tag, then click Generate DataSet. The Generate Dataset dialog box appears.

18.  Verify that the Existing radio button is selected, the Products table is selected, and the option Add this dataset to the designer is selected, and then click OK.

The nwindDataSet1 is added to the component tray.

Add a second OleDbDataAdapter

19.  From the Toolbox, double-click the OleDbDataAdapter component to add another OleDbDataAdapter component to the component tray.

20.  Select the data connection that shows the directory, ACCESS. C:\Program Files\ComponentOne\Studio for Winforms \Common\Nwind.mdb from the drop-down listbox.

21.  Click Next to continue.

22.  Verify the Use SQL statements is selected and then click Next.

23.  Copy and paste the following SQL statement in the textbox of the Data Adapter Configuration Wizard:

SELECT CategoryName, CategoryID FROM Categories

24.  Click Next and then click Finish.

Generate a DataSet for OleDbDataAdapter2

Generate a DataSet that is related to OleDbDataAdapter2 by completing the following steps:

25.  Select OleDbDataAdapter2 and click on its smart tag, and then click Generate DataSet.

26.  In the Generate Dataset dialog box, click New, and then name it categoriesDataSet.

27.  Verify that the Categories table is selected and that the option Add this dataset to the designer is selected, and then click OK.

The categoriesDataSet1 is added to the component tray.

Fill the datasets

To fill the DataSets, add the following code in the Form1_Load event:

      Visual Basic

      C#

Add the DataView component

Return to Design view, and complete the following steps:

28.  From the Toolbox, double-click the DataView component to add it to the component tray.

Note: In Visual Studio 2005, right-click the Toolbox, and then click Choose Items. On the .NET Framework Components tab in the dialog box, select DataView.

29.  In the DataView Properties window set the properties to the following:

      AllowDelete = False

      AllowEdit = False

      AllowNew = False

      Table = nwindDataSet1.Products

Congratulations! You have successfully created a data source. The next step will show you how to add a chart and bind it to the existing data source as well as how to easily customize your chart using the Chart Properties designer.


Send us comments about this topic.
Copyright © GrapeCity, inc. All rights reserved.