Visual Basic 6 Black Book:Databases: Using DAO, RDO, And ADO
function GetCookie (name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg) {
var end = document.cookie.indexOf (";", j);
if (end == -1)
end = document.cookie.length;
return unescape(document.cookie.substring(j, end));
}
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
var m1='';
var gifstr=GetCookie("UsrType");
if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; }
document.write(m1+m2+m3);
Keyword
Title
Author
ISBN
Publisher
Imprint
Brief
Full
Advanced Search
Search Tips
Please Select
-----------
Components
Content Mgt
Certification
Databases
Enterprise Mgt
Fun/Games
Groupware
Hardware
IBM Redbooks
Intranet Dev
Middleware
Multimedia
Networks
OS
Prod Apps
Programming
Security
UI
Web Services
Webmaster
Y2K
-----------
New Titles
-----------
Free Archive
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
function isIE4()
{
return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') );
}
function bookMarkit()
{
var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0";
parent.location.href=url;
//var win = window.open(url,"myitk");
//if(!isIE4())
// win.focus();
}
Search this book:
Previous
Table of Contents
Next
Connecting A Data Control To A Bound Control
In 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.
TIP: Set the text boxs DataSource and DataField properties after adding and connecting the data control. When you do, youll find the text boxs 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.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.
Figure 24.9 Using a data control to move through a database.
Registering An ODBC Source
The 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.
Figure 24.10 The Create New Data Source dialog box.
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.
Figure 24.11 The ODBC Microsoft Access dialog box.
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.
Figure 24.12 The ODBC Data Source Administrator.
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 Control
To add a new remote 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 Remote Data Control entry in the Controls list box.
4. Click on OK to close the Components dialog box.
5. This adds the Remote Data Control tool to the toolbox; draw that control as you want it on your form.
6. Connect the remote data control to an ODBC data source with the DataSource property.
7. Create a result set (unlike data controls and ADO data controls, which use record sets, remote data controls use result sets) that you can work with by supplying an SQL statement in the SQL property.
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.
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.
Wyszukiwarka
Podobne podstrony:
2009 10 27 Wstęp do SI [w 04]id&835838 841838 (2)838 841M P 13 835mbdch20 838836 838mbdch20 835więcej podobnych podstron