BookRags.com Literature Guides Literature
Guides
Criticism & Essays Criticism &
Essays
Questions & Answers Questions &
Answers
Lesson Plans Lesson
Plans
My Bibliography Periodic Table U.S. Presidents Shakespeare Sonnet Shake-Up
Research Anything:        
History | Encyclopedias | Films | News | Create a Bibliography | More... Login | Register | Help
Not What You Meant?  There are 2 definitions for ADODB.

ActiveX Data Objects

Print-Friendly
About 3 pages (945 words)

Bookmark and Share Know this topic well? Help others and get FREE products!

Contents

Definition

Microsoft ActiveX Data Objects (ADO) is a set of Component Object Model objects for accessing data sources. It provides a layer between programming languages and OLE DB (a means of accessing data stores, whether they be databases or otherwise, in a uniform manner), which allows a developer to write programs which access data, without knowing how the database is implemented. You must be aware of your database for connection only. No knowledge of SQL is required to access a database when using ADO, although one can use ADO to execute arbitrary SQL commands. The disadvantage of this (i.e. using SQL directly) is that it introduces a dependency upon the type of database used. It is positioned as a successor to Microsoft's earlier object layers for accessing data sources, including RDO (Remote Data Objects) and DAO (Data Access Objects). ADO was introduced by Microsoft in October 1996. ADO consists of several top-level objects:

  • Connection Object - represents the connection to the database.
  • Recordset Object - represents a set of database records.
  • Command Object - represents a SQL command.
  • Record Object - represents a set of data, typically from a source other than a database.
  • Stream Object - represents a stream of data, as from a text file or web page.
  • Error Object - stores errors.
  • Field Object - represents a database field.
  • Parameter Object - represents a SQL parameter.
  • Property Object - stores information about objects.

The ADO components are usually used in conjunction with a high-level language such as VBScript in an ASP environment or Visual Basic. However, languages such as Delphi and C++ Builder, development environments from Microsoft rival Borland Software Corporation, also allow the use of ADO to access various databases. In the newer programming framework of .NET, Microsoft also presented an upgraded version of ADO called ADO.NET. Its object structure is quite different from that of traditional ADO.

Basic Usage

Some basic steps are required in order to be able to access and manipulate data using ADO :

  1. Create a connection object to connect to the database.
  2. Create a recordset object in order to receive data in.
  3. Open the connection
  4. Populate the recordset by opening it and passing the desired table name or SQL statement as a parameter to open function.
  5. Do all the desired searching/processing on the fetched data.
  6. Commit the changes you made to the data (if any) by using Update or UpdateBatch methods.
  7. Close the recordset
  8. Close the connection

ASP Example

Here is an ASP example using ADO to select the "Name" field, from a table called "Phonebook", where a "PhoneNumber" was equal to "555-5555".

dim myconnection, myrecordset, name
set myconnection = server.createobject("ADODB.Connection")
set myrecordset = server.createobject("ADODB.Recordset")

myconnection.open mydatasource
myrecordset.open "Phonebook", myconnection
myrecordset.find "PhoneNumber = '555-5555'"
name = myrecordset.fields.item("Name")
myrecordset.close

set myrecordset = nothing
set myconnection = nothing

This is equivalent to the following ASP code, which uses plain SQL instead of the functionality of the Recordset object:

dim myconnection, myrecordset, name
set myconnection = server.createobject("ADODB.connection")
myconnection.open mydatasource
set myrecordset = myconnection.execute("SELECT Name FROM Phonebook WHERE PhoneNumber = '555-5555'")
name = myrecordset(0)

VBA Example

This is a Microsoft Access VBA example to update a name of an item, from a table called "items", where "item_code" is equal to "GI8293-23"

Dim myconnection as new ADODB.Connection
Dim myrecordset as new ADODB.Recordset
Set myconnection = CurrentProject.AccessConnection
myrecordset.Open "items", myconnection, adOpenKeyset, adLockOptimistic, adCmdTable
myrecordset.find "item_code = 'GI8293-23'"
if (not myrecordset.EOF)  'If the specified criteria cannot be satisfied, then the current record is EOF
    myrecordset!item_name = "My New Item"
end if
myrecordset.update       'Actually commit the update to the data source
myrecordset.close
myconnection.close

Software support

ADO is supported in ASP and in VBA for Office.

See also

ADO.NET

External links

View More Summaries on ActiveX Data Objects
 
Ask any question on ActiveX Data Objects and get it answered FAST!
Answer questions in BookRags Q&A and earn points toward
discounted or even FREE Study Guides and other BookRags products!
Learn more about BookRags Q&A
Copyrights
ActiveX Data Objects from Wíkipedia. ©2006 by Wíkipedia. Licensed under the GNU Free Documentation License. View a list of authors or edit this article.

Article Navigation
Join BookRagslearn moreJoin BookRags




About BookRags | Customer Service | Report an Error | Terms of Use | Privacy Policy