|
|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
Connecting A Data Control To A Bound ControlIn the previous few topics, we connected a database to a 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 data control, set the text boxs DataSource property to the name of the data control (or remote data control or ADO 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 data control weve developed over the previous few topics. Add a text box, Text1, to the program now and set its DataSource property to Data1. When you move through the database with the data control, the 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.9. Using the data control, you can move to the beginning or end of the database, and step through record by record as well. Congratulationsnow youre working with databases. The code for this example is located in the dao folder on this books accompanying CD-ROM.
Registering An ODBC SourceThe Testing Department is calling again. Your program with the data control, SuperDuperDataBase, is terrific, but what if you want to work with an ODBC database? Hmm, you think, is that possible? It is, with the remote data control. You can use an ODBC data source with a remote data control, but first you have to configure a new connection for the ODBC source. You configure an ODBC connection with the 32-bit ODBC item in your computers control panel. Open that item now, click the System DSN tab (DSN stands for data source name), and click the Add button to open the Create New Data Source dialog box you see in Figure 24.10.
You can see the ODBC drivers installed on your system in this dialog box. Select the one you want to use and click Finish; to install the db.mdb file weve developed in the previous few topics, well select the Microsoft Access Driver entry here. This opens the ODBC Microsoft Access dialog box you see in Figure 24.11. Use the Select button to select the database file, db.mdb in our example, and click on the OK button in the ODBC Microsoft Access dialog box. We give the name db to this source.
This creates a new ODBC connection for our file, and that connection appears in the ODBC Data Source Administrator, as shown in Figure 24.12.
Click on the OK button to close the ODBC Data Source Administrator. Now youve added a new ODBC source to your computers data environment. Well use this data source, db, in the next topic. Opening A Database With A Remote Data ControlTo add a new remote data control to a form, follow these steps:
Lets see an example. Add a remote data control, MSRDC1, to a form now. Well connect it to the db ODBC data source weve created in the previous few topics, and you do that by setting the remote data controls DataSourceName property to db. Unlike the data control or the ADO data control, you need to create a result set to work with in the remote data control, and we create a result set by selecting the entire students table with the SQL statement SELECT * FROM students. Place that string in the controls SQL property. Now weve connected our database to the remote data controlbut how do we connect the remote data control to bound controls? Well look at that in the next topic.
|
|
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. |