Carapace

ActiveX Data Objects -- ADO

This is meant as a brief introduction to the major ADO objects -- the full documentation from Microsoft can be found in the Internet Client SDK.

ADODB.Connection object

This is the connection onto the database. Most of the data manipulation is done via the Command and RecordSet objects.

Important properties:

property name property type description
connectionString String identifies the datasource to connect to
isolationLevel Integer defines the effect of holding a record set open on other users -- the default value is 'cursor stability' which means the use of transactions ensure only committed data can be seen/modified

Important methods:

method name description
open open the connection onto the data source
execute execute the supplied SQL command
close close the connection onto the data source
beginTrans start a transaction
commitTrans commit a transaction
rollbackTrans rollback a transaction

ADODB.Command object

The Command object is used to execute general commands on the data within the database. These commands can have parameters - for example, the command may be a database insert command: the parameters are then the data elements to insert.

Important properties:

property name property type description
activeConnection Dispatch identifies the current database connection
commandText String the SQL statement to be performed

Important methods:

method name description
execute execute the SQL command and return a record set -- the data can then be viewed or further manipulated using this RecordSet object

ADODB.RecordSet object

The RecordSet object resembles a window onto a set of data contained in the database. This window can be used for viewing the data as well as modifying it.

The record set can be created directly using the create function or as a return value from the execute method on an ADO Command object.

Important properties:

property name property type description
activeConnection Dispatch identifies the current database connection
fields Dispatch This is a collection of ADODB.Field objects. Each such Field object has a name and a value. Enumeration of this collection shows all values in the current row of the record set.

The data in the row can be modified by setting the value of the appropriate field entry, and calling the update method on the record set.

Note that the lockType property of the record set must be set to something other than the default for an update to be allowed, since the default is to treat the data as 'read only'.

commandText String the SQL statement to be performed

Important methods:

method name description
moveFirst move to the first row of the record set
moveNext move to the next row of the record set
movePrevious move to the previous row of the record set
update update the database to reflect modifications to the fields collection property of the record set
addNew insert a new row into the database at the current point in the record set -- the data in the row is made from the supplied fields collection
delete delete the current row of the record set from the database


Contents Index Current topic: databases Related topics: objects, functions