2. Universal Data Access
• Open Database Connectivity (ODBC)
– standard for accessing data in databases
• OLE-DB
– allows access to data in many formats
– faster and easier to use than ODBC
4. ADO, DAO and RDO in Visual Basic
• In Visual Basic, three data access interfaces are
available to you:
– ActiveX Data Objects (ADO)
– Remote Data Objects (RDO)
– Data Access Objects (DAO)
• Data access technology is constantly evolving, and
each of the three interfaces represents a different
stage of development for data access technology.
• The latest is ADO. It features a simpler — yet
more flexible — object model than either RDO or
DAO. For new projects, you should use ADO as
your data access interface.
5. The ADO Object Model
• Four main objects:
* Connection – the link between the program
and the data store
* Command – allows you to run commands
against the data store
* Recordset – contains all the data returned from
a specific action on the data store
* Stream – allows the manipulation of data held
in web resources, such as HTML files
6. Using the ADO Data Control
• Add the Microsoft ADO Data Control 6.0 (OLEDB)
component to your project.
• Create an instance of the ADO Data Control on your
form.
• Connect to a database with the ADO Data Control by
building a connection string.
• Set the RecordSource property of the ADO Data
Control
• Create bound controls on your form.
7. Building a Connection String
• In the properties window of the ADO Data
control’s choose the ConnectionString property.
• 3 Methods
• From the property pages, choose Use Connection
String and choose Build
• From the Provider tab in the Data Link Properties
dialog box, specify which data provider to use.
– use Microsoft Jet 4.0 OLE DB Provider for Access
databases
– choose Next >> to bring up the Connection tab of the
Data Link Properties dialog box
8. Building a Connection String
• Three methods
– Use a data Data Link File
– Use an ODBC Data Source Name
– Use a Connection String
Back
9. Building a Connection String
• From the Connection tab, enter your
database name and path (or browse for it)
• Leave the default log on
information
• Test Connection
10. Set the RecordSource property of
the ADO Data Control
• In the properties window of the ADO Data control’s
choose the RecordSource property.
• Choose a Command Type
– adCmdUnknown
– adCmdTable
– adCmdText
– adCmdStoredProc
• Select a table or enter
an SQL statement
11. Creating Bound Controls
• Many different controls that can hold text
and graphics can be bound to a field in an
ADO Data control.
• Set the DataSource property of the bound
control to the ADO Data Control.
• Set the DataField property of the bound
control to the field you want to display
Notas do Editor
Each OLE-DB data provider is a unit of code, written in a language such as C++ or Java which uses OLE-DB objects to provide the instructions required to communicate and pass data between the data store and the data provider.
ActiveX Data Objects (ADO) sits between the application itself and the OLE-DB layer. In our case, it’s the interface between the ASP code and the OLE-DB provider. You can use ADO with any COM-compliant programming language such as Visual Basic, Visual C++, or Java.
DAO (Data Access Objects) was the first object-oriented interface that exposed the Microsoft Jet database engine (used by Microsoft Access) and allowed Visual Basic developers to directly connect to Access tables - as well as other databases - through ODBC. DAO is suited best for either single-system applications or for small, local deployments.
(Remote Data Objects) is an object-oriented data access interface to ODBC combined with the easy-to-use style of DAO, providing an interface that exposes virtually all of ODBC’s low-level power and flexibility. RDO is limited, though, in that it doesn't access Jet or ISAM databases very well, and that it can access relational databases only through existing ODBC drivers. However, RDO has proven to be the interface of choice for a large number of SQL Server, Oracle, and other large relational database developers.
ODBC (Open Database Connectivity) A standard protocol for database servers providing a common language for Windows applications to gain access to a database on a network. You install ODBC drivers for various databases that enable you to connect to the databases and access their data.
The five main objects have a “flat” hierarchy which means that you can create any ADO object without the need to create a hierarchy of parent and grandparent objects. For example, you can use a Recordset object to make a direct request from the data store without creating an explicit Connection object in your code first.
To add the ADO data control, right click the toolbox, choose components and add Microsoft ADO Data Control 6.0 (OLEDB)
Connection information can be stored in a separate file known as a connection file or data link files. This file has a suffix of “.uld”. You can build connection files from the Control Panel.
Another option is to use an existing ODBC data source or create a new one. With this option, you can establish a connection to multiple types of databases using the Open Database Connectivity (ODBC) standards.
The third option is to build a connection string. This option takes advantage of the OLE DB and ADO. As the OLE DB and ADO technologies are much newer than ODBC, fewer vendors support OLE DB.
The options on the Connection tab will vary depending on the provider selected. These options assist you in building the string stored into the ConnectionString property.
The contents of the Advanced tab will also vary depending upon the provider selected. This tab contains other options to configure the data link.
The All tab allows you to manually set each of the options pertaining to the data link.
The command type is initially set to adCmdUnknown, indicating that the type of command is unknown.
When set to adCmdTable, the RecordSource property consists of the name of the database table.
When set to adCmdText, the RecordSource property is viewed as a text string. This string typically contains an SQL statement.
When set to adCmdStoredProc, the command type is a stored procedure. A stored procedure is used with an SQL server and contains a precompiled SQL statement.
You will need a separate ADO Data Controls on your form for each table or query you need to access.