Executing Commands

You can execute a command with the Command object, the Connection object, or the Recordset object. Command objects allow you the greatest flexibility by allowing you to specify how the returned Recordset is defined. Connection objects and Recordset objects offer very little fine-tuning capabilities, but they are excellent for retrieving simple recordsets using the default settings.

Executing Commands with the Command Object

A command can be executed with a Command object by using its Execute method. The Execute method has three parameters. The first is a number indicating how many records were affected by the command once it had been executed. If the command being executed deleted records, this number would indicate how many were deleted. If it was a command to update records, this number would indicate how many were updated. The second is an array of variant data representing one or more parameter values (parameters are discussed in the next section of this chapter). The third is an integer value representing a CommandTypeEnum value listed in Table 7-1 and an optional ExcecuteOptionEnum value.

The ExecuteOptionEnum value used with the Execute method of the Command object allows you to specify how a provider should execute a command. The valid values for the ExecuteOptionEnum enumeration can be found in Table 7-2.

Table 7-2. The ExecuteOptionEnum Enumeration

Enumeration (ADO/WFC)

Value

Description

AdAsyncExecute (ASYNCEXECUTE)
16 (&H10)

Instructs ADO to execute ...

Get ADO: ActiveX Data Objects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.