Syntax
On a Command object:
Set recordset = command.Execute(RecordsAffected, Parameters, Option)
command.Execute RecordsAffected, Parameters, Option
On a Connection object:
Set recordset = connection.Execute(CommandText, RecordsAffected, Option)
connection.Execute CommandText, RecordsAffected, Option
The Execute method syntax has these parts.
Part |
Description |
recordset |
An object variable representing the Recordset object in which the results of the query are stored. |
command |
An object variable representing a Command object whose CommandText property contains the query to execute. |
connection |
An object variable representing a Connection object on which the query is executed. |
RecordsAffected |
Optional. A Long variable to which the provider returns the number of records that the operation affected. |
Parameters |
Optional. A Variant array of parameter values passed with an SQL statement. (Output parameters are not allowed in this argument.) |
CommandText |
A String containing the SQL statement, query, or stored procedure to execute. |
Option |
Optional. A Long expression that indicates how the provider should evaluate the CommandText argument. Can be one of the following constants: |
adCmdUnknown, 0 - The type of command in the CommandText argument is not known. adCmdText, 1 - Evaluate CommandText as a textual definition of a command. adCmdTable, 2 - Evaluate CommandText as a table name. adCmdStoredProc, 4 - Evaluate CommandText as a stored procedure. | |
See the CommandType property for a more detailed explanation of these constants. |
Remarks
Use the Execute method to execute an existing Command object or a query of your choosing. You can also specify a Recordset object in which to store the results, if any.
Command
Using the Execute method on a Command object executes the query specified in the CommandText property of the object. If the CommandText property 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 does not create a Recordset object and only returns a Null object reference. Most application languages allow you to ignore this return value if no Recordset is desired.
If the query has parameters, the current values for the Command object's parameters are used unless you override these with parameter values passed with the Execute call. You can override a subset of the parameters by omitting new values for some of the parameters when calling the Execute method. The order in which you specify the parameters is the same order in which the method passes them. For example, if there were four (or more) parameters and you wanted to pass new values for only the first and fourth parameters, you would pass varArray(var1,,,var4) as the Parameters argument.
Note You cannot pass output parameters with the Parameters argument.
Connection
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 does not create a Recordset object and only returns a Null object reference. Most application languages allow you to ignore this return value if no Recordset is desired.
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.