Sun Chili!Soft ASP Sun Chili!Soft
ASP Sun Microsystems

 

ADO Recordset Object Open Method

Opens a cursor.

Open Method Syntax

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

Open Method Parameters

Source

An optional Variant that evaluates to a valid Command object variable name, an SQL statement, a table name, or a stored procedure call.

ActiveConnection

An optional Variant that evaluates to a valid Connection object variable name, or a String containing ConnectionString parameters.

CursorType

An optional CursorTypeEnum value that determines the type of cursor that the provider should use when opening the recordset. Can be one of the following constants (See the ADO Recordset Object CursorType Property for definitions of these settings.):

Constant

Description

adOpenForwardOnly

Default. Opens a forward-only cursor.

adOpenKeyset

Opens a keyset cursor.

adOpenDynamic

Opens a dynamic cursor.

adOpenStatic

Opens a static cursor.

LockType

An optional LockTypeEnum value that determines what type of locking (concurrency) the provider should use when opening the recordset. Can be one of the following constants (See the LockType property for more information.):

Constant

Description

adLockReadOnly

Default. Read-only; you cannot alter the data.

adLocPessimistic

Pessimistic locking, record by record. The provider does what is necessary to ensure successful editing of the records, usually by locking records at the data source immediately upon editing.

adLockOptimistic

Optimistic locking, record by record. The provider uses optimistic locking, locking records only when you call the Update method.

adLockBatchOptimistic

Optimistic batch updates. Required for batch update mode as opposed to immediate update mode.

Options

An optional Long value that indicates how the provider should evaluate the Source argument if it represents something other than a Command object. Can be one of the following constants (See the CommandType property for a more detailed explanation of these constants.):

Constant

Description

adCmdText

The provider should evaluate Source as a textual definition of a command.

adCmdTable

The provider should evaluate Source as a table name.

adCmdStoredProc

The provider should evaluate Source as a stored procedure.

adCmdUnknown

The type of command in the Source argument is not known.

See the ADO Command Object CommandType Property for a more detailed explanation of the four constants in this list.

Open Method Remarks

Using the Open method on a Recordset object opens a cursor that represents records from a base table or the results of a query.

Use the optional Source argument to specify a data source using one of the following: an ADO Command Object variable, an SQL statement, a stored procedure, or a table name.

The ActiveConnection argument corresponds to the ActiveConnection property and specifies in which connection to open the Recordset object. If you pass a connection definition for this argument, ADO opens a new connection using the specified parameters. You can change the value of this property after opening the recordset to send updates to another provider. Or, you can set this property to Nothing (in Microsoft Visual Basic) to disconnect the recordset from any provider.

For the other arguments that correspond directly to properties of a Recordset object (Source, CursorType, and LockType), the relationship of the arguments to the properties is as follows:

   The property is read/write before the Recordset object is opened.

   The property settings are used unless you pass the corresponding arguments when executing the Open method. If you pass an argument, it overrides the corresponding property setting, and the property setting is updated with the argument value.

   After you open the Recordset object, these properties become read-only.

Note

For Recordset objects whose ADO Recordset Object Source Property is set to a valid Command object, the ActiveConnection property is read-only, even if the Recordset object isn't open.

If you pass a Command object in the Source argument and also pass an ActiveConnection argument, an error occurs. The ActiveConnection property of the Command object must already be set to a valid ADO Connection Object or connection string.

If you pass something other than a Command object in the Source argument, you can use the Options argument to optimize evaluation of the Source argument. If the Options argument is not defined, you may experience diminished performance because ADO must make calls to the provider to determine if the argument is an SQL statement, a stored procedure, or a table name. If you know what Source type you're using, setting the Options argument instructs ADO to jump directly to the relevant code. If the Options argument does not match the Source type, an error occurs.

If the data source returns no records, the provider sets both the ADO Recordset Object BOF, EOF Properties to True, and the current record position is undefined. You can still add new data to this empty Recordset object if the cursor type allows it.

When you have concluded your operations over an open Recordset object, use the ADO Recordset Object Close Method to free any associated system resources. Closing an object does not remove it from memory; you may change its property settings and use the Open method to open it again later. To completely eliminate an object from memory, set the object variable to Nothing.

Open Method Examples

See the ADO Recordset Object Close Method.

Copyright 2002 Sun Microsystems, Inc. All rights reserved. Legal Notice.