|
|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
Connecting A Remote Data Control To A Bound ControlIn the previous topic, we connected a database to a remote data control. To see that data, well use a data-bound controla text box. Well investigate all the data-bound controls later in this chapterafter weve gone through the ways of connecting to databasesso this is just to get us started. To connect a text box to a remote data control, set the text boxs DataSource property to the name of the remote data control. To display a particular field in the text box, place that fields name in the text boxs DataField property. Lets see an example. Here, well use the database, db.mdb, and the remote data control weve 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 fields name in the text boxs DataField property; here, well place the Name field in that property.
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. Congratulationsnow youre working with ODBC databases. The code for this example is located in the rdo folder on this books accompanying CD-ROM.
Opening A Database With An ADO Data ControlTo add a new ADO data control to a form, follow these steps:
Lets see an example. Here, well connect an ADO data control to the database weve 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;"
Next, set the ADO data controls RecordSource property to the table to work with, which is students in our example database, db.mdb. Now youve 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 ControlIn the previous topic, we connected a database to an ADO data control. To see that data, well use a data-bound controla text box. Well investigate all the data-bound controls later in this chapterafter weve gone through the ways of connecting to databasesso this is just to get us started. To connect a text box to an ADO data control, set the text boxs DataSource property to the name of the remote data control. To display a particular field in the text box, place that fields name in the text boxs DataField property. Lets see an example. Here, well 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 fields name in the text boxs DataField property; here, well place the Name field in that property.
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. Congratulationsnow youre working with ADO databases. The code for this example is located in the ado folder on this books accompanying CD-ROM.
|
|
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. |