Execute Method (Command) ADO

Executes the query, SQL statement, or stored procedure specified in the CommandText property.

Applies To

Command

Required Files

msado15.dll
VC: adoint.h, adoid.h

Syntax

For a row-returning command:

Set recordset = command.Execute(RecordsAffected, Parameters, Options)

For a non row-returning command:

command.Execute RecordsAffected, Parameters, Options

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 will not return correct values when passed in this argument.)
Options Optional. A CommandTypeEnum value that indicates how the provider should evaluate the CommandType property of the Command object. Can be one of the following constants:
  • adCmdText — Evaluate CommandText as a textual definition of a command, such as an SQL statement.

  • adCmdTable — Evaluate CommandText as a table name.

  • adCmdStoredProc — Evaluate CommandText as a stored procedure.

  • adCmdUnknown — The type of command in the CommandText argument is not known.

  • adRunAsync — Execute the Command asynchronously. This constant can be used with any of the other four constants.
See the CommandType property for a more detailed explanation of these constants.

Remarks

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 returns a closed Recordset object. Most application languages allow you to ignore this return value if no Recordset is desired.

If the Options argument is set to adRunAsync, the RecordsAffected parameter will always return adUnknown (= -1) since the provider has no way of knowing how many rows will be affected.

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 Array(var1,,,var4) as the Parameters argument.

Note Output parameters will not return correct values when passed in the Parameters argument.

Examples

Execute, Requery, Clear Methods Example (VB)

© 1997 Microsoft Corporation. All rights reserved. Terms of Use.