Open

This method defines and opens recordsets; runs SQL commands.

Syntax

recordset.Open Source, ActiveConnection, CursorType, LockType, Options

Parameters

Source

Required. Variant that is a table name or an SQL statement.

ActiveConnection

Optional. Specifies the .cdb file opened on the device: \sample.cdb. This parameter is available on the following platforms: H/PC Pro, P/PC 1.2, and Platform Builder 2.12.

CursorType

Optional. Determines what movement through the recordset is enabled and how updates to the underlying database are reflected in the Recordset object. It is one of the values described in the following table.

Constant Value Description
adOpenForwardOnly 0 Forward-only cursor. Identical to a static cursor except that you can only scroll forward through records. In the current Windows CE-based model, this cursor type does not improve performance. For compatibility with ADO for the desktop computer, however, it remains the default.
adOpenKeyset 1 Keyset cursor. Additions, changes, and deletions by other users are not visible. All types of movement through the recordset are enabled.

Using other values results in a LockType of 1 (adOpenKeyset). Dynamic-type and static-type cursors are not available in ADOCE.

LockType

Optional. Determines what type of locking, or concurrency, the provider should use when opening the Recordset. It is one of the values described in the following table.

Constant Value Description
adLockReadOnly 1 Default—you cannot add, delete, or change records.
adLockOptimistic 3 You can add, delete, and change records.

Using other values results in a LockType of 3 (adLockOptimistic), unless the table itself is read-only. In that case, the LockType is 1 (adLockReadOnly). For compatibility with ADO for the desktop computer, the default LockType is 1 (adLocklReadOnly). Pessimistic and optimistic batch locking are unavailable in ADOCE.

Options

Optional. Indicates how the provider should evaluate the Source parameter. It is one of the values described in the following table.

Constant Value Description
adCmdText 1 Evaluates Source as an SQL statement.
adCmdTable 2 Evaluates Source as a table name from MSysTables.
adCmdStoredProc 4 Evaluates Source as a stored procedure from MSysProcs.
adCmdUnknown 8 Default—the type of command in the Source parameter is unknown.

Remarks

The Open method is read-only by default.

No Command object exists in ADOCE, so the Source parameter must be a string.

No Connection object exists in ADOCE, and the object store is the only possible connection. The ActiveConnection parameter, if specified, must be a zero-length string ("").

If you know what type of command you are using, setting the Options parameter instructs ADOCE to go directly to the relevant code. If the Options parameter does not match the type of command in the Source parameter, an error occurs when you call the Open method.

When the Open method is called with a non-row-returning SQL command such as CREATE TABLE, no recordset is returned and the state of the recordset remains closed.

Example

The following code example sets CursorType and LockType constants for the Open method.

Const adOpenKeyset = 1
Const adLockOptimistic = 3

Dim rstLocked, rstUpdateable
Set rstLocked = CreateObject("adoce.recordset")
Set rstUpdateable = CreateObject("adoce.recordset")

'The default is to open a read-only, forward-only recordset
rstLocked.Open "myTable"
'Sadditional parameters for write acccess to a recordset
rstUpdateable.Open "myTable2","", adOpenKeyset, adLockOptimistic