Home arrow Visual Basic arrow Page 2 - Implementing An ADO Data Control With VB6

Implementing An ADO Data Control With VB6

The ADO data control can save Visual Basic developers hours of time. In this article Susan shows us exactly how to go about implementing an ADO control.

Author Info:
By: Susan Harkins
Rating: 4 stars4 stars4 stars4 stars4 stars / 147
June 15, 2002
  1. · Implementing An ADO Data Control With VB6
  2. · What is a data control?
  3. · Adding the remaining controls
  4. · Conclusion

print this article

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.
blog comments powered by Disqus

- Developing an XML Web Service Using Visual S...
- Creating an HTML File List with VB
- Fun with Email: VB6, CDO, MAPI, and a Remote...
- Extranet/Intranet Dictionary Cracker in VB
- Finding Default App Icons With Visual Basic
- Registry Fever With Visual Basic
- Implementing An ADO Data Control With VB6
- Printing With Visual Basic
- MSMQ Part 1/2: Architecture and Simple Imple...
- Magnifying The Desktop With Visual Basic
- Sending Email With MAPI Components in Visual...
- Two Person Chat With The Winsock Control And...
- A Real-Time ActiveX News Control
- Accessing the Windows API in Visual Basic

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials