Implementing An ADO Data Control With VB6 - What is a data control? (Page 2 of 4 )
The ADO data control presents a fast and easy way to create a bound form by providing built-in functions that define, navigate, display, add to, and update the records in a recordset. The resulting form makes it easy for a user (non-developer) to maintain records. Although the data control defines the recordset, you'll still need a control for each field to automatically display the bound records.
The image above displays a simple form with several bound controls. The data control at the bottom of the form contains four navigation buttons. These buttons, from left to right, allow you to move to the first, previous, next, and last records in the form's recordset. If you update a record, VB will save that change when you move to another record. If you close the form before moving to another record. VB won't save changes you've made to the current record.
Creating A Bound Form Now, let's create the form shown in the previous image. First, launch a new standard .exe project, insert a form, and change that form's name to frmDataControl. Then, save the project as DataControl.
Adding the ADO data control The control you'll be working with in this article isn't the data control you're accustomed to. The control on the Toolbox is for backward compatibility when running applications created in older versions of VB. The data control we'll be working with (the new ADO version) is available via the Components option. To add the ADO data control to the Toolbox, press Ctrl+T to open the Components dialog box. Select MS ADO Data Control 6.0 (OLEDB), and click Apply, and then click Close. Once you’ve added the ADO data control to the toolbox, you can add one to the bottom of your form (fromDataControl). Name the new control adoData.
Connecting adoData to a Jet database At this point you must establish where the data control will find its records. You have more than one option. You can connect the data control to an SQL Server or a Jet database. For our example, we're going to connect to a Jet database; the Nwind.mdb database (MS Access) that comes with VB. To get started, we'll need to change a few of our ADO data control's default properties. Refer to the table below for those settings.
Now you're ready to set the ConnectionString property. First, select the ConnectionString property field and then click the resulting Build button. Choose the Use Connection String option (if it isn't already selected). Next, click that option's Build button to display the Data Link Properties dialog box. Then, choose Microsoft Jet 3.51 OLE DB Provider in the Provider tab. At this point, select the Connection tab and identify the database you're connecting to in the Select or enter a database name control.
We connected to C:\Program Files\Microsoft Visual Studio\VB98Nwind.mdb Of course, your setup will probably be different, so be sure to specify the correct path to your database file. To test the connection, click the Test Connection button at the bottom of the dialog box. If the connection is sound, click OK twice to return to your form. If the connection fails, you'll need to adjust the entry until it works.