CdbRecordset::OpenRecordset Method

Creates a new Recordset object and appends it to the Recordsets collection.

Syntax

CdbRecordsetOpenRecordset(LONG lType=-1, LONG lOption=-1);

Parameters

Type Example Description
LONG lType Optional. A constant that indicates the type of Recordset to open as listed in Settings.
LONG lOption Optional. A combination of constants that specify characteristics of the new Recordset as listed in Settings.

Settings

Use the following values for Type.

Constant Description
dbOpenTable Opens a table-type Recordset object (Microsoft Jet workspaces only).
dbOpenDynamic Opens a dynamic-type Recordset object, which is similar to an ODBC dynamic cursor. (ODBCDirect workspaces only)
dbOpenDynaset Opens a dynaset-type Recordset object, which is similar to an ODBC keyset cursor.
dbOpenSnapshot Opens a snapshot-type Recordset object, which is similar to an ODBC static cursor.
dbOpenForwardOnly Opens a forward-only-type Recordset object.

 

Use the following values for Option.

Constant Description
dbAppendOnly Allows users to append new records to the Recordset, but prevents them from editing or deleting existing records (Microsoft Jet dynaset-type Recordset only).
dbSQLPassThrough Passes an SQL statement to a Microsoft Jet-connected ODBC data source for processing (Microsoft Jet snapshot-type Recordset only).
dbSeeChanges Generates a run-time error if one user is changing data that another user is editing (Microsoft Jet dynaset-type Recordset only). This is useful in applications where multiple users have simultaneous read/write access to the same data.
dbDenyWrite Prevents other users from modifying or adding records (Microsoft Jet Recordset objects only).
dbDenyRead Prevents other users from reading data in a table (Microsoft Jet table-type Recordset only).
dbForwardOnly Creates a forward-only Recordset (Microsoft Jet snapshot-type Recordset only). It is provided only for backward compatibility, and you should use the dbOpenForwardOnly constant in the type argument instead of using this option.
dbReadOnly Prevents users from making changes to the Recordset (Microsoft Jet only). The dbReadOnly constant in the lockedits argument replaces this option, which is provided only for backward compatibility.
dbRunAsync Runs an asynchronous query (ODBCDirect workspaces only).
dbExecDirect Runs a query by skipping SQLPrepare and directly calling SQLExecDirect (ODBCDirect workspaces only). Use this option only when you’re not opening a Recordset based on a parameter query. For more information, see the "Microsoft ODBC 3.0 Programmer’s Reference."
dbInconsistent Allows inconsistent updates (Microsoft Jet dynaset-type and snapshot-type Recordset objects only).
dbConsistent Allows only consistent updates (Microsoft Jet dynaset-type and snapshot-type Recordset objects only).

Remarks

The constants dbConsistent and dbInconsistent are mutually exclusive. Using both causes an error.

Note The core topic says the LockEdits parameter is available for all OpenRecordset methods. The CdbRecordset::OpenRecordset method actually applies to Microsoft Jet workspaces only. The LockEdits parameter actually applies to ODBCDirect workspaces only and is not available in this method.

Usage

#include <afxole.h>
#include <dbdao.h>
CdbDBEngine      dben;
CdbDatabase      dbs;
CdbRecordset      rst, rst2;

dbs = dben.OpenDatabase(_T("Northwind.mdb"));
rst = dbs.OpenRecordset(_T("SELECT * FROM EMPLOYEES"),dbOpenDynaset);
   // Get more selective.
rst.SetFilter(_T("LASTNAME >= 'M'");
rst2 = rst.OpenRecordset();