ADO Command Object

The ADO Command object is a definition of a specific command that is to be executed against an OLE DB data source.

Command objects can be used to create a Recordset object and obtain records, to execute a bulk operation, or to manipulate the structure of a database. When using the Microsoft® OLE DB Provider for AS/400 and VSAM, some collections, methods, or properties of a Command object may generate an error when called.

The primary purpose of the Command object in the context of the OLE DB Provider for AS/400 and VSAM is to issue AS/400 Command Language (CL) commands for execution by the remote OS/400 DDM target server. Legal DDM command-line strings are documented in Chapter 5 of the AS/400 DDM User's Guide published by IBM.

The following Command object methods, properties, and collections are supported by the current version of the OLE DB Provider for AS/400 and VSAM:

Name Comment
Execute method Evaluates command text as a text string (only supported Options parameter for this method is adCmdText which indicates that this is not an SQL command).
ActiveConnection property Sets or returns the information used to establish a connection to a data source (see notes following).
CommandText property Sets or returns the command text to be executed.
CommandType property Sets or returns the type of command in a CommandText property.
Name property Assigns a name to or retrieves the name of a Command object.
State property Describes the current state of an object.
Properties collection Collections of properties on the command.

The Execute method executes a command and returns a Recordset object if appropriate with the Execute method. The Command object can be used to open tables or execute DDM commands on a remote DDM server. If errors occur, these can be examined with the Errors collection on the Connection object.

A Command object can be created independently of a previously defined Connection object by setting the ActiveConnection property of the Command object to a valid connection string (see the ConnectionString property of the Connection object for the proper syntax). ADO still creates a Connection object, but it does not assign that object to an object variable. However, if multiple Command objects are to be associated with the same connection, the Connection object should be explicitly created and opened. This assigns the Connection object to an object variable. If the ActiveConnection property of the Command object is not set to this object variable, ADO creates a new Connection object for each Command object, even if the same connection string is used.

The ActiveConnection property associates an open connection with a Command object. The CommandText property defines the text version of a command (an EXEC COMMAND DDMCmd statement, for example, where DDMCmd represents a valid AS/400 CL command). The CommandType property specifies the type of command described in the CommandText property prior to execution in order to optimize performance. The CommandType property must be set to adCmdText for use with OLE DB Provider for AS/400 and VSAM.

The Command object can also be used to open a data file after a Connection object has been opened and the ActiveConnection property has been set to this open connection. The CommandText property defines the data file to open (an EXEC OPEN DataSetName statement, for example, where DataSetName represents a valid data file or library member on the host). The CommandType property must be set to adCmdText for use with the OLE DB Provider for AS/400 and VSAM. If you open a host data file from a Command object, then the data file is opened as read-only. This results from the limitation that no argument or option is passed by ADO that supplies a parameter describing whether the data set should be opened as read-only or updatable.