These methods are optimized to take advantage of the strengths of their particular objects.
Before you issue a command, you must open a connection. Each method that issues a command represents the connection differently:
The Connection.Execute method uses the connection embodied by the Connection object itself.
The Command.Execute method uses the Connection object set in its ActiveConnection property.
The Recordset.Open method specifies either a connect string or Connection object operand, or uses the Connection object set in its ActiveConnection property.
Another difference is the way the command is specified in the three methods:
In the Connection.Execute method, the command is a string.
In the Command.Execute method, the command isn't visibleùit's specified in the Command.CommandText property. Furthermore, the command can contain parameter symbols (æ?Æ) which will be replaced by the corresponding parameter in the Parameters VARIANT array argument.
In the Recordset.Open method, the command is the Source argument, which can be a string or a Command object.
Each method trades off functionality versus performance:
The Execute methods are intended forùbut are not limited toùexecuting commands that don't return data.
Both Execute methods return fast but static-cursor, forward-only Recordset objects.
The Command.Execute method allows you to use parameterized commands that can be reused efficiently.
On the other hand, the Open method allows you to specify the CursorType(strategy and object used to access the data); and LockType (specify the degree of isolation from other users, and whether the cursor should support updates in immediate or batchmodes).
We advise you to study these options; they embody much of the functionality of a Recordset.
This tutorial uses a dynamic cursor to batch any changes to the Recordset. For this reason, use the following:
Recordset rs = New ADODB.Recordset
rs.Open cmd, conn, adOpenDymanic, adLockBatchOptimistic