ADO » Objects » Command

The ADO Command object is used to submit and execute a specific (single) query against a database. The query can command a variety of actions, such as adding, creating, deleting, retrieving, or updating databases (record sets).

If the query is used to retrieve data, then the data will be returned as a RecordSet object. This means that the retrieved data can be manipulated by the sixty-four properties, collections, methods, and events that belong to the Recordset object. Also with ADO 2.6, the performance of command queries that only return a single row has been greatly improved.

One of the major features of the Command object is the ability to use stored queries and procedures that accept parameters. This requires access to the Parameter collection, which is a collection that is unique to the Command object.

You can also use the Execute method of the Connection object or the Open method of the RecordSet object to query a database. However, these queries lack the great versatility offered by the properties, collections, methods, and events that are associated with the Command object. (For example, you cannot use parameterized queries.)



Syntax: Set connectionobject = commandobject. ActiveConnection
Set commandobject.ActiveConnection = connectionobject
commandobject.ActiveConnection = string
string = commandobject.ActiveConnection

Sets or returns a variant value defining the Connection object to which the Command object belongs, or returns a string value if there is no connection.


Syntax: commandobject.CommandStream = string
string = commandobject.CommandStream

Identifies the Stream object containing the command details.


Syntax: commandobject.CommandText = string
string = commandobject.CommandText

Sets or returns the text of a command statement to be applied against a data provider.


Syntax: commandobject.CommandTimeout = long
long = commandobject.CommandTimeout

The number of seconds to wait while attempting to execute a command, before cancelling the attempt and generating an error.


Syntax: commandobject.CommandType = CommandTypeEnum
CommandTypeEnum = commandobject.CommandType

Sets or returns the CommandTypeEnum type of the Command object.


Syntax: commandobject.Dialect = string
string = commandobject.Dialect

Sets or returns the dialect to be used for the CommandStream or CommandTextproperties.


Syntax: commandobject.Name = string
string = commandobject.Name

Sets or returns the string name of the Command object.


Syntax: commandobject.NamedParameters = boolean
boolean = commandobject.NamedParameters

Sets or returns a boolean that determines whether or not parameter names should be passedto the provider.


Syntax: commandobject.Prepared = Boolean
Boolean = commandobject.Prepared

Sets or returns a Boolean value that indicates whether or not the provider is to save a compiled version of a command before it is executed.


Syntax: long = commandobject.State

Returns a long value describing if the Command object is open, closed or in the process of connecting, executing or retrieving.



Syntax: commandobject.Cancel

Cancels the execution of a pending Execute call.


Syntax: Set parameterobject = commandobject.CreateParameter (Name, Type, Direction, Size, Value)

Creates a new Parameter object.


Syntax: Syntax for non-row-returning:
commandobject.Execute RecordsAffected, Parameters, Options

Syntax for row-returning:
Set recordsetobject = commandobject.Execute (RecordsAffected, Parameters, Options)

Executes the query, SQL statement or stored procedure.



The Parameters Collection is a collection of the Parameter objects associated with a specific Command object. Each Parameter object provides detailed information about a single parameter used in a stored procedure or a parameterized query.


The Properties Collection is a collection of Property objects. Each Property object contains a single piece of information, called a dynamic property, about the database provider. By referring to the Properties Collection, each connection to a provider can be tailored specifically by ADO to suit the exact needs of that provider.

See Also: