ActiveX Data Objects
![]() | This article includes a list of references, related reading, or external links, but its sources remain unclear because it lacks inline citations. (February 2013) |
In computing, Microsoft's ActiveX Data Objects (ADO) comprises a set of Component Object Model (COM) objects for accessing data sources. A part of MDAC (Microsoft Data Access Components), it provides a middleware layer between programming languages and OLE DB (a means of accessing data stores, whether databases or not, in a uniform manner). ADO allows a developer to write programs that access data without knowing how the database is implemented; developers must be aware of the database for connection only. No knowledge of SQL is required to access a database when using ADO, although one can use ADO to execute SQL commands directly (with the disadvantage of introducing a dependency upon the type of database used).
Microsoft introduced ADO in October 1996, positioning the software as a successor to Microsoft's earlier object layers for accessing data sources, including RDO (Remote Data Objects) and DAO (Data Access Objects).
Internals
ADO is made up of four collections and twelve objects.
ADO collections
- Fields
- This collection contains a set of Field objects. The Collection can be used in either a Recordset object or in a Record object. In a Recordset object, each of the Field objects that make up the Fields collection corresponds to a column in that Record set object. In a Record object, a Field can be an absolute or relative URL that points into a tree-structured namespace (used for semi-structured data providers like the Microsoft OLE DB Provider for Internet Publishing) or as a reference to the default Stream object associated with that Record object.
- Properties
- An object can have more than one Property object, which are contained in the object's Properties collection.
- Parameters
- A Command object can have several Parameter commands to change its predefined behaviour, and each of the Parameter objects are contained in the Command object's Parameters collection
- Errors
- All provider-created errors are passed to a collection of Error objects, while the Errors collection itself is contained in a Connection object. When an ADO operation creates an error, the collection is cleared and a new group of Error objects is created in the collection.
Sinhgad Instute of buisness managment
Basic usage
Some basic steps are required in order to be able to access and manipulate data using ADO :
- Create a connection object to connect to the database.
- Create a recordset object in order to receive data in.
- Open the connection
- Populate the recordset by opening it and passing the desired table name or SQL statement as a parameter to open function.
- Do all the desired searching/processing on the fetched data.
- Commit the changes you made to the data (if any) by using Update or UpdateBatch methods.
- Close the recordset
- 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)
Software support
ADO is supported in ASP, Delphi, PowerBuilder, and in Visual Basic for Applications (VBA). ADO support has now been added to dBase Plus 8 (With ADO)