CdbDatabase::Execute Method

Runs an SQL statement on a specified Database object.

Syntax

VOIDExecute(LPCTSTR pstrQuery,

LONG lOption=-1);

Parameters

Type Example Description
LPCTSTR pstrQuery A pointer to a string that is an SQL statement.
LONG lOption Optional. A constant or combination of constants that determines the data integrity characteristics of the query, as specified in Remarks.

Remarks

The following are valid Option values.

Constant Description
dbDenyWrite Denies write permission to other users (Microsoft Jet workspaces only).
dbInconsistent (Default) Executes inconsistent updates (Microsoft Jet workspaces only).
dbConsistent Executes consistent updates (Microsoft Jet workspaces only).
dbSQLPassThrough Executes an SQL pass-through query. Setting this option passes the SQL statement to an ODBC database for processing (Microsoft Jet workspaces only).
dbFailOnError Rolls back updates if an error occurs (Microsoft Jet workspaces only).
dbSeeChanges Generates a run-time error if another user is changing data you are editing (Microsoft Jet workspaces only).

Usage

#include <afxole.h>
#include <dbdao.h>

CdbWorkspace      ws;
CdbDatabase      db;
...                  // Initialize ws, db, etc.

ws.BeginTrans();      // Start working.
db.Execute(_T("SELECT * FROM PARTS"),  dbFailOnError);     
                     // Make some changes.
ws.CommitTrans();       // Accept changes.
ws.Close();            // Close the workspace