MDAC 2.5 SDK - ADO


 

Step 3: Execute the Command (ADO Tutorial)

See Also

You are Here...

Discussion

The three methods that return a Recordset are Connection.Execute, Command.Execute, and Recordset.Open. This is their syntax in Visual Basic:

connection.Execute(CommandText, RecordsAffected, Options)
command.Execute(RecordsAffected, Parameters, Options)
recordset.Open Source, ActiveConnection, CursorType, LockType, Options

These methods are optimized to take advantage of the strengths of their particular objects.

Before you issue a command, you must implicitly or explicitly open a connection. Each method that issues a command represents the connection differently:

Another difference is the way the command is specified in the three methods:

Each method trades off functionality versus performance:

Study these options; they embody much of the functionality of a Recordset. Of particular importance is the decision to use the Microsoft Cursor Service for OLE DB. Please refer to Microsoft Cursor Service for OLE DB for details about the implications of this decision.

This tutorial will make changes to the Recordset in batch mode; therefore, a LockType of adLockBatchOptimistic is specified. Batch processing requires the Cursor Service, so the CursorLocation property is set to adUseClient. Since the Command object is already set to an open connection, the ActiveConnection parameter cannot be specified in the Open method.

The Recordset is declared and used like this:

Dim rs As New ADODB.Recordset
rst.CursorLocation = adUseClient
rst.Open cmd, , adOpenStatic, adLockBatchOptimistic

Next   Step 4: Manipulate the Data