The Open Method

This method opens the Recordset object and retrieves the data specified by the Source argument. The Open method has the following syntax:

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

The Source argument tells the recordset what data it should retrieve. This is most commonly a SQL string or the name of a stored procedure, but can also be the name of a table or a Command object.

The ActiveConnection argument can be a connection string or a Connection object that identifies the connection to be used. If you assign a connection string to the ActiveConnection argument, the recordset will create a Connection object for itself.

The CursorType argument specifies the type of cursor to use when opening the recordset. This is set using one of the CursorTypeEnum values. This chapter uses only the adOpenForwardOnly and adOpenStatic cursor types. The first type will be used for normal queries, and using it means that the recordset can be navigated in only one direction, from beginning to end, which is the fastest method for accessing data. Note that the data in a forward-only recordset cannot be modified. The second type will be used for disconnected recordsets and allows complete navigation. If you do not specify a cursor type, adOpenForwardOnly is the default.

The LockType argument specifies what type of locks the provider should place on the underlying data source when opening the recordset. This is set using one of the LockTypeEnum values. This chapter uses only the following two lock types, corresponding to normal and disconnected recordsets, respectively: adLockReadOnly and adLockBatchOptimistic.

The Options argument here is the same as the Options argument covered in the Connection object's Execute method earlier in the chapter. It is used to tell the provider how to interpret and execute the contents of the Source argument.

0 0

Post a comment