Execute Method (ADO Connection)

See Also   Example   Applies To   

Executes the specified query, SQL statement, stored procedure, or provider-specific text.

Syntax

For a non–row-returning command string:

connection.Execute CommandText, RecordsAffected, Options

For a row-returning command string:

Set recordset = connection.Execute (CommandText, RecordsAffected, Options)

Return Value

Returns a Recordset object reference.

Parameters

CommandText   A String containing the SQL statement, table name, stored procedure, or provider-specific text to execute.

RecordsAffected   Optional. A Long variable to which the provider returns the number of records that the operation affected.

Options   Optional. A Long value that indicates how the provider should evaluate the CommandText argument. Can be one of the following values.

Constant Description
adCmdText Indicates that the provider should evaluate CommandText as a textual definition of a command.
adCmdTable Indicates that ADO should generate an SQL query to return all rows from the table named in CommandText.
adCmdTableDirect Indicates that the provider should return all rows from the table named in CommandText.
adCmdTable Indicates that the provider should evaluate CommandText as a table name.
adCmdStoredProc Indicates that the provider should evaluate CommandText as a stored procedure.
adCmdUnknown Indicates that the type of command in the CommandText argument is not known.
adExecuteAsync Indicates that the command should execute asynchronously.
adFetchAsync Indicates that the remaining rows after the initial quantity specified in the CacheSize property should be fetched asynchronously.

See the CommandType property for a more detailed explanation of the first four constants in this list.

Remarks

Using the Execute method on a Connection object executes whatever query you pass to the method in the CommandText argument on the specified connection. If the CommandText argument specifies a row-returning query, any results the execution generates are stored in a new Recordset object. If the command is not a row-returning query, the provider returns a closed Recordset object.

The returned Recordset object is always a read-only, forward-only cursor. If you need a Recordset object with more functionality, first create a Recordset object with the desired property settings, then use the Recordset object’s Open method to execute the query and return the desired cursor type.

The contents of the CommandText argument are specific to the provider and can be standard SQL syntax or any special command format that the provider supports.

An ExecuteComplete event will be issued when this operation concludes.