Adding a New Data Source
-
From the Visual Studio PROJECT menu, select Add New Data Source.
Data Source Configuration Wizard appears.
-
Select Database, then click Next.
-
Select Dataset, then click Next.
-
Click New Connection.
-
Select Data source as Microsoft Access Database File (OLE DB).
-
Click Browse for adding Database file name as C1NWind.mdb.
-
Navigate to the default location of C1NWind.mdb database (located by default in C:\Users\Documents\ComponentOne Samples\Common), then click Open, and then click OK.
-
Click Next.
A dialog box appears to check 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.
-
Verify that the Yes, save the connection as check box is checked and click Next to continue.
The connection string is saved as C1NWindConnectionString
-
Expand the Tables node, and then select the Categories and the Products object.
-
Click Finish.
C1NWindDataSet.xsd is added to the project.
Adding a OleDbDataAdapter
- From the Visual Studio Toolbox, double-click the OleDbDataAdapter component.
|
In Visual Studio, right-click anywhere inside the Toolbox, and then select Choose Items. On the .NET Framework Components tab in the dialog box, select OleDbDataAdapter |
.
oleDbDataAdapter1 is added to the component tray and Data Adapter Configuration Wizard appears.
- Select the connection you wish to use for the data adapter from the drop-down listbox (in this case, C:\Users\Documents\ComponentOne Samples\Common\C1NWind.mdb), and then click Next.
Use SQL statements is clicked by default.
- Click Next.
- Copy and paste the following SQL statement in the textbox of Data Adapter Configuration Wizard:
SELECT CategoryID, ProductName, UnitPrice, UnitsInStock, ReorderLevel FROM Products ORDER BY UnitPrice DESC
- Click Next, then click Yes to add primary key columns to your query.
- Click Finish.
oleDbConnection1 is added to the component tray.
Generating a DataSet
- Select oleDbDataAdapter1, then click on its smart tag, and then click Generate DataSet.
Generate Dataset appears.
- Verify that the Existing radio button is clicked, the Products table is selected, and Add this dataset to the designer is selected, and then click OK.
c1NWindDataSet1 is added to the component tray.
Adding Another OleDbDataAdapter
- From the Visual Studio Toolbox, double-click the OleDbDataAdapter component and Data Adapter Configuration Wizard appears.
oleDbDataAdapter2 is added to the component tray.
- Select the data connection that shows the directory, ACCESS. C:\Users\Documents\ComponentOne Samples\Common\C1NWind.mdb from the drop-down listbox.
- Click Next.
- Verify that Use SQL statements is clicked, and then click Next.
- Copy and paste the following SQL statement in the textbox of Data Adapter Configuration Wizard:
SELECT CategoryName, CategoryID FROM Categories
- Click Next, and then click Finish.
Generating a DataSet for the Second OleDbDataAdapter
- Select oleDbDataAdapter2, then click on its smart tag, and then click Generate DataSet.
- In Generate Dataset, click New, and then name it as categoriesDataSet.
- Verify that the Categories table is selected, Add this dataset to the designer is selected, and then click OK.
categoriesDataSet1 is added to the component tray.
Filling the DataSets
To fill the datasets, add the following code in the Form1_Load event:
Title Text |
Copy Code
|
Type your code here. |
Adding the DataView Component
- From the Visual Studio Toolbox, double-click the DataView component.
|
In Visual Studio, right-click anywhere inside the Toolbox, and then select Choose Items. On the .NET Framework Components tab in the dialog box, select DataView.
|
dataView1 is added to the component tray.
- Select dataView1.
- In the DataView Properties window, set the following properties as given below:
AllowDelete = False
AllowEdit = False
AllowNew = False
Table = c1nwindDataSet1.Products
A new data source is created successfully.