Share via


Visual Basic Concepts

Running the MyDataControl Project

In the previous topic, we added the code that allows the MyData control to provide data to other objects. In this step we'll connect the MyData control to an ADO source and bind to it using both simple and complex binding.

Note   This topic is part of a series that walks you through creating sample data source components. It begins with the topic Creating Data Sources.

To test the MyData control

  1. If it's still open, close the MyData designer and open the designer for Form1.

  2. Select the MyData control and switch to the Properties window.

  3. Double-click the ConnectionString property and enter the DSN connection string for the Northwind database. It should look something like this: DSN = Northwind.

    Important   If you haven't previously created a DSN for the Northwind database, you'll need to create one first.The procedure for creating a DSN is discussed in "Connection Objects" in "About the Data Environment Designer" in the Data Access Guide.

  4. Double-click the RecordSource property and enter Customers. This specifies the Customers table in the Northwind database; you could also enter a SQL statement here in order to filter the data.

  5. Select a TextBox control in the Toolbox and add it to Form1, then switch to the Properties window.

  6. Select the DataSource property and choose MyData1 from the drop-down list.

  7. Select the DataField property. The drop-down list should contain a list of the fields in the Customers table. Select the CompanyName field.

  8. Select Start from the Run menu to run the project.

    As you click the buttons on the MyData control, names from the CompanyName field should appear in the TextBox. Try editing a name in the TextBox, then move forward and back to the same record. You'll notice that your change has been saved to the database. The TextBox is simple-bound to the Northwind database by way of the MyData control.

  9. Stop the project (by selecting End from the Run menu), then select the form.

  10. Choose Components from the Project menu to open the Components dialog. Check the Microsoft Data Grid 6.0 to add it to your project, then click OK.

  11. Select the DataGrid in the Toolbox and add it to Form1, then switch to the Properties window.

  12. Select the DataSource property and set it to MyData1.

  13. Select Start from the Run menu to run the project.

    The grid should contain all of the data from the Customers table. As you click the buttons on the MyData control, the selected row in the grid changes to match the data in the TextBox, scrolling as necessary. As with the TextBox, you can edit data in the grid and the changes are saved in the database. The DataGrid is complex-bound to the Northwind database by way of the MyData control.

  14. Stop the project (by selecting End from the Run menu), then select the MyData control on Form1.

  15. In the Properties window, double-click the ConnectionString property and enter an OLE DB connection string, such as Provider=Microsoft.Jet.OLE DB.3.51;Data Source=c:\northwind.mdb.

    Important   If you haven't previously created a OLE DB connection for the Northwind database, you'll need to create one first.The procedure for creating a DSN is discussed in "Creating the Northwind OLEDB Data Source" in "Using Visual Basic's Standard Controls" in the Programmer's Guide.

  16. Select Start from the Run menu to run the project.

    You'll see that the data looks and acts exactly like it did before. The data is now being accessed through an OLE DB interface rather than a ODBC interface, and all you had to do was change the connection string!

As long as you have the project open, take some time to play around with other property settings such as BOFAction and EOFAction to see their behavior.

In the next few steps, we'll build a ActiveX DLL and connect our form to an OLE DB Simple Provider.

Step by Step

This topic is part of a series that walks you through creating sample ActiveX data sources.

To See
Go to the next step Creating the MyData Component Project
Start from the beginning Creating Data Sources