CDaoDatabase::Execute

void Execute( LPCTSTR lpszSQL, int nOptions = 0 );
throw( CDaoException, CMemoryException );

Parameters

lpszSQL

Pointer to a null-terminated string containing a valid SQL command to execute.

nOptions

An integer that specifies options relating to the integrity of the query. You can use the bitwise-OR operator (|) to combine any of the following constants (provided the combination makes sense — for example, you would not combine dbInconsistent with dbConsistent):

Note   If both dbInconsistent and dbConsistent are included or if neither is included, the result is the default. For an explanation of these constants, see the topic "Execute Method" in DAO Help.

Remarks

Call this member function to run an action query or execute an SQL statement on the database. Execute works only for action queries or SQL pass-through queries that do not return results. It does not work for select queries, which return records.

For a definition and information about action queries, see the topics "Action Query" and "Execute Method" in DAO Help.

Tip   Given a syntactically correct SQL statement and proper permissions, the Execute member function will not fail even if not a single row can be modified or deleted. Therefore, always use the dbFailOnError option when using the Execute member function to run an update or delete query. This option causes MFC to throw an exception of type CDaoException and rolls back all successful changes if any of the records affected are locked and cannot be updated or deleted. Note that you can always call GetRecordsAffected to see how many records were affected.

Call the GetRecordsAffected member function of the database object to determine the number of records affected by the most recent Execute call. For example, GetRecordsAffected returns information about the number of records deleted, updated, or inserted when executing an action query. The count returned will not reflect changes in related tables when cascade updates or deletes are in effect.

Execute does not return a recordset. Using Execute on a query that selects records causes MFC to throw an exception of type CDaoException. (There is no ExecuteSQL member function analogous to CDatabase::ExecuteSQL.)

For more information about using the Execute member function, see the article DAO Querydef: Using Querydefs in Visual C++ Programmer's Guide.

CDaoDatabase OverviewClass MembersHierarchy Chart