CdbConnection::Execute Method

Runs an action query or executes an SQL statement on a specified Connection object.

Syntax

VOIDExecute(LPCTSTR pstrQuery,

LONG lOption=-1);

Parameters

Type Example Description
LPCTSTR pstrQuery A pointer to a string that is an SQL statement or the Name property value of a QueryDef object.
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 values for Option.

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).
dbRunAsync Executes the query asynchronously (ODBCDirect Connection and QueryDef objects only).
dbExecDirect Executes the statement without first calling SQLPrepare ODBC API function (ODBCDirect Connection and QueryDef objects only).

Usage

#include <afxole.h>
#include <dbdao.h>
CdbQueryDef       qd;
CdbConnection   conn;
LPCTSTR          lpctsrSQL = 
   _T("SELECT SALARY FROM EMPLOYEES WHERE LASTNAME = 'SMITH'");
...
qd = conn.CreateQueryDef(_T("SALARYDEF"), lpctsrSQL);
conn.Execute(_T("SALARYDEF"), dbFailOnError);