METHOD:  Recordset::Open

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

The Open method is called on a Recordset object to open a cursor which gives you access to the records contained in the base table, the results from a query, or a previously saved Recordset.

When you are done with the Recordset, you should call Close.

There are five optional parameters.

The optional Source parameter is a variant that can be any one of the following data sources:
  • Command object
  • SQL query string
  • table name
  • stored procedure call
  • URL
  • full or relative path/file name
  • Stream object containing a Recordset
The optional ActiveConection parameter is either a connection string that defines the connection, or it is a variant that contains the valid Connection object associated with the Recordset. If you pass a Command object in the Source parameter, you cannot use this parameter since the ActiveConection property of of the Command must already be set.

The optional CursorType parameter is one of the CursorTypeEnum constants that specifies the type of cursor to use when you open a Recordset object.

CursorTypeEnum Constants
 
Constant Value Description
adOpenDynamic 2 A dynamic cursor with both forward and backward scrolling where additions, deletions, insertions, and updates made by other users are visible
adOpenForwardOnly 0 Default, a forward scrolling only, static cursor where changes made by other users are not visible
adOpenKeyset 1 A keyset cursor allows you to see dynamic changes to a specific group of records but you cannot see new records added by other users
adOpenStatic 3 A static cursor allowing forward and backward scrolling of a fixed, unchangeable set of records
adOpenUnspecified -1 Cursor type not specified

 
The optional LockType parameter is one of the LockTypeEnum constants that indicates the type of lock in effect on a Recordset. The default is adLockReadOnly.

LockTypeEnum Constants
 
Constant Value Description
adLockBatchOptimistic 4 Multiple users can modify the data and the changes are cached until BatchUpdate is called
adLockOptimistic 3 Multiple users can modify the data which is not locked until Update is called
adLockPessimistic 2 The provider locks each record before and after you edit, and prevents other users from modifying the data
adLockReadOnly 1 Read-only data
adLockUnspecified -1 Lock type unknown

 
The optional Options parameter tells the provider how to evaluate the Source parameter when it contains something other than a Command object. The appropriate use of this option can speed up performance since ADO will not have to determine the type of the data source. It can be one or more of the following CommandTypeEnum or ExecuteOptionEnum constants.
 
CommandTypeEnum Constants
 
Constant Value Description
adCmdFile 256 Evaluate as a previously persisted file
adCmdStoredProc 4 Evaluate as a stored procedure
adCmdTable 2 Have the provider generate an SQL query and return all rows from the specified table
adCmdTableDirect 512 Return all rows from the specified table
adCmdText 1 Evaluate as a textual definition
adCmdUnknown 8 The type of the CommandText parameter is unknown
adCmdUnspecified -1 Default, does not specify how to evaluate

 
ExecuteOptionEnum Constants
 
Constant Value Description
adAsyncFetch 32 Records are fetched asynchronously
adAsyncFetchNonBlocking 64 Records are fetched asynchronously without blocking the return

 
Code (VBScript):
Set objRecordset = Server.CreateObject("ADODB.Recordset")
Set objRecordset.ActiveConnection = strConnection
objRecordset.CursorLocation = adUseClient
objRecordset.CursorType = adOpenDynamic
objRecordset.Open "GuruChants", , , , adCmdTable
Or
objRecordset.Open "SELECT ChantTitles FROM GuruChants", strConnection, _
   adOpenDynamic, adLockBatchOptimistic, adCmdTable

Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information