Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Visual Basic 6 Black Book
(Publisher: The Coriolis Group)
Author(s): Steven Holzner
ISBN: 1576102831
Publication Date: 08/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Connecting A Remote Data Control To A Bound Control

In the previous topic, we connected a database to a remote data control. To see that data, we’ll use a data-bound control—a text box. We’ll investigate all the data-bound controls later in this chapter—after we’ve gone through the ways of connecting to databases—so this is just to get us started.

To connect a text box to a remote data control, set the text box’s DataSource property to the name of the remote data control. To display a particular field in the text box, place that field’s name in the text box’s DataField property.

Let’s see an example. Here, we’ll use the database, db.mdb, and the remote data control we’ve in the previous topic. Add a text box, Text1, to the program now, and set its DataSource property to the remote data control, MSRDC1.

When you move through the database with the remote data control, the remote data control will hold the current record; to display a field in the current record, place that field’s name in the text box’s DataField property; here, we’ll place the Name field in that property.


TIP:  Set the text box’s DataSource and DataField properties after adding and connecting the remote data control. When you do, you’ll find the text box’s DataSource and DataField properties can be set with drop-down list boxes in the Properties window, making that process easier.

When we run the program, we get the result in Figure 24.13. Using the remote data control, you can move to the beginning or end of an ODBC database and step through record by record as well. Congratulations—now you’re working with ODBC databases. The code for this example is located in the rdo folder on this book’s accompanying CD-ROM.


Figure 24.13  Opening a database with the remote data control.

Opening A Database With An ADO Data Control

To add a new ADO data control to a form, follow these steps:

1.  Select the Project|Components menu item.
2.  Click the Controls tab in the Components dialog box that opens.
3.  Select the Microsoft ADO Data Control entry in the Controls list box.
4.  Click on OK to close the Components dialog box.
5.  This adds the ADO data control tool to the toolbox; draw that control as you want it on your form.
6.  Connect the ADO data control’s Connection object to a data source with the ConnectionString property, separating items in that string with semicolons. At the least, you should specify the Provider (the type of OLE DB) and Data Source (database name) values in the ConnectionString. See the following material for more information.

Let’s see an example. Here, we’ll connect an ADO data control to the database we’ve constructed in the early parts of this chapter, db.mdb. To do that, add an ADO data control, Adodc1, to a form, and set its ConnectionString property to specify the data provider type and the data source for that database like this:

"PROVIDER=Microsoft.Jet.OLEDB.3.51;Data Source=c:\vbbb\ado\db.mdb;"


TIP:  One way of connecting an ADO control to a database easily is with the Data Form Wizard, which generates the connection string for you automatically. We’ll see more of this wizard later in this chapter.

Next, set the ADO data control’s RecordSource property to the table to work with, which is students in our example database, db.mdb.

Now you’ve connected a database to the ADO data control. To connect the ADO data control to bound controls, see the next topic.

Connecting An ADO Data Control To A Bound Control

In the previous topic, we connected a database to an ADO data control. To see that data, we’ll use a data-bound control—a text box. We’ll investigate all the data-bound controls later in this chapter—after we’ve gone through the ways of connecting to databases—so this is just to get us started.

To connect a text box to an ADO data control, set the text box’s DataSource property to the name of the remote data control. To display a particular field in the text box, place that field’s name in the text box’s DataField property.

Let’s see an example. Here, we’ll use the database, db.mdb, and the ADO data control we developed over the previous few topics. Add a text box, Text1, to the program now, and set its DataSource property to the ADO data control, Adodc1. When you move through the database with the ADO data control, the ADO data control will hold the current record; to display a field in the current record, place that field’s name in the text box’s DataField property; here, we’ll place the Name field in that property.


TIP:  Set the text box’s DataSource and DataField properties after adding and connecting the remote data control. When you do, you’ll find the text box’s DataSource and DataField properties can be set with drop-down list boxes in the Properties window, making that process easier.

When we run the program, we get the result in Figure 24.14. Using the ADO data control, you can move to the beginning or end of databases, and step through record by record as well. Congratulations—now you’re working with ADO databases. The code for this example is located in the ado folder on this book’s accompanying CD-ROM.


Figure 24.14  Opening a database with the ADO data control.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.