You are on page 1of 6

Using Data Sources (ODBC)

You can use Data Sources Open Database Connectivity (ODBC) to access data from a variety of database
management systems. For example, if you have a program that accesses data in a SQL database, Data
Sources (ODBC) will let you use the same program to access data in a Visual FoxPro database. To do this,
you must add software components called drivers to your system. Data Sources (ODBC) helps you add
and configure these drivers.

How to: Open the ODBC Data Source Administrator

Use the ODBC Data Source Administrator to create and manage ODBC data sources. The ODBC Data
Source Administrator is a Windows component.

To open the ODBC Data Source Administrator in Windows XP Professional

1. On the Start menu, click Control Panel.

2. In Control Panel (Category View), click Performance and Maintenance, and then click Administrative
Tools, or in Control Panel (Classic View), click Administrative Tools.

3. In Administrative Tools, click Data Sources (ODBC).

http://msdn.microsoft.com/en-us/library/ms188691.aspx

Visual Basic & ADO Tutorial


This tutorial describes how you can use ADO objects in VB6. Now days, almost any time you write full
fledged database application you will want to use ADO. Along with this, as your applications become
more and more complex you will probably not want to rely on Visual Basic's data controls, but instead
use the ADO objects directly. Read on to find out exactly how this can be done.

Originally Written By TheVBProgramer.

The "Alphabet Soup" of Database Access

Prior to VB6 and the introduction of ADO (ActiveX Data Objects), VB programmers would generally use
DAO (Data Access Objects) to interact with local databases such as MS Access and use RDO (Remote
Data Objects) to interact with client/server databases such as Oracle and SQL Server. The concept
behind Visual Basic ADO was Universal Data Access (UDA), where one database access method could
be used for any data source; it was designed to replace both DAO and RDO. DAO remains a viable
technology for interacting with MS Access databases as it is faster than ADO for that purpose; however,
ADO is more flexible – using ADO, one could develop a prototype database application using MS Access
in the back-end, and with a "flick of the wrist" (i.e., with very little coding changes) "upsize" that same
application to use Oracle or SQL Server. As far as RDO is concerned, no new versions of it have been
developed beyond the version that shipped with Visual Basic, and there are no future plans for it.

In the VB4 and VB5 worlds, RDO was the main method used to interact with client/server databases.
RDO works perfectly fine with VB6, so when folks migrated their VB5 applications over to VB6, little or no
coding changes were required. However, ADO is the preferred method of database access for new VB6
applications .

About this Tutorial

This tutorial presents three small sample applications using ADO. All three applications use a local MS
Access database.

The first sample application introduces the ADO Data Control (ADODC) which demonstrates a "quick and
dirty" way to connect to a remote database. The second and third applications use ADO code: the second
allows navigation and searching of a database table; the third allows navigation and updating on a
database table. All three connect to an ODBC Data Source, which must be set up through the Windows
Control Panel. How to do this is described below.

Note: If you have previously set up a DSN for the Biblio database as described in the previous topic on
RDO, you can skip the section on setting up an ODBC data source and resume here.

Setting Up an ODBC Data Source

Follow the steps below to set up an ODBC Data Source (this process is also called "setting up a DSN",
where "DSN" stands for "Data Source Name"). These steps assume Windows 2000 for the operating
system. On other versions of Windows, some steps may vary slightly.

         Via Windows Control Panel, double-click on Administrative Tools, then Data Sources (ODBC).


The ODBC Data Source Administrator screen is displayed, as shown below. Click on the System
DSN tab.

 
 

         Click the Add button. The Create New Data Source dialog box will appear. Select Microsoft
Access Driver (*.mdb)from the list and click the Finish button.

 
 

         The ODBC Microsoft Access Setup dialog box will appear. For Data Source Name, type Biblio. If
desired, you can type an entry for Description, but this is not required.

         Click the Select button. The Select Database dialog box appears. On a default installation of VB6 or


Visual Studio 6, the BIBLIO.MDB sample database should reside in the folder C:\Program
Files\Microsoft Visual Studio\VB98. Navigate to that folder, select BIBLIO.MDB from the file list,
and click OK.

 
 

Note: If VB was installed in a different location on your system, navigate to the appropriate folder. If you
do not have the BIBLIO.MDB sample database file on your system at all, you can download
it here. In that case, copy the file to the folder of your choice, and navigate to that folder to select
the database for this step.

         When you are returned to the ODBC Microsoft Access Setup screen, the database you selected
should be reflected as shown below. Click OK to dismiss this screen.

         When you are returned to the ODBC Data Source Administrator screen, the new DSN should appear
as shown below. Click OK to dismiss this screen.

 
 

At this point, the Biblio database is ready to be used with RDO in the sample application.

All Tutorials is in here:

http://www.vb6.us/tutorials/database-access-ado-vb6-tutorial

You might also like