Visual Basic: RDO Data Control

Execute Method (Remote Data)

See Also    Example    Applies To

Runs an action query or executes an SQL statement that does not return rows.

Syntax

connection**.Execute** source[, options]

query**.Execute** [options]

The Execute method syntax has these parts:

Part Description
connection An object expression that evaluates to the rdoConnection object on which the query will run.
query An object expression that evaluates to the rdoQuery object whose SQL property setting specifies the SQL statement to execute.
source A string expression that contains the action query to execute or the name of an rdoQuery.
options A Variant or constant that determines how the query is run, as specified in Settings.

Settings

You can use the following constants for the options argument:

Constant Value Description
rdAsyncEnable 32 Execute operation asynchronously.
rdExecDirect 64 (Default.) Bypass creation of a stored procedure to execute the query. Uses SQLExecDirect instead of SQLPrepare and SQLExecute.

Remarks

It is recommended that you use the Execute method only for action queries. Because an action query doesnt return any rows, Execute doesnt return an rdoResultset. You can use the Execute method on queries that execute multiple statements, but none of these batched statements should return rows. To execute multiple result set queries that are a combination of action and SELECT queries, use the OpenResultset method.

Use the RowsAffected property of the rdoConnection or rdoQuery object to determine the number of rows affected by the most recent Execute method. RowsAffected contains the number of rows deleted, updated, or inserted when executing an action query. When you use the Execute method to run an rdoQuery, the RowsAffected property of the rdoQuery object is set to the number of rows affected.

Options

To execute the query asynchronously, use the rdAsyncEnable option (which is set by default). If set, the data source query processor immediately begins to process the query and returns to your application before the query is complete. Use the StillExecuting property to determine when the query processor is ready to return the results from the query. Use the Cancel method to terminate processing of an asynchronous query.

To bypass creation of a temporary stored procedure to execute the query, use the rdExecDirect option. This option is required when the query contains references to transactions or temporary tables that only exist in the context of a single operation. For example, if you include a Begin Transaction TSQL statement in your query or reference a temporary table, you must use rdExecDirect to ensure that the remote engine is not confused when these objects are left pending at the end of the query.

While it is possible to execute stored procedures using the Execute method, it is not recommended because the procedures return value and output parameters are discarded and the procedure cannot return rows. Use the OpenResultset method against an rdoQuery to execute stored procedures.

Note   When executing stored procedures that do not require parameters, do not include the parenthesis in the SQL statement. For example, to execute the "MySP" procedure use the following syntax: {Call MySP }.

Also, a call like:

   rCn.Execute SqlStatement, rdAsyncEnable +  
   rdExecDirect

allows only one outstanding request and allows Visual Basic code to overlap with SQL Server processing, but doesn't allow multiple outstanding SQL Server requests.