CopyQueryDef Method

See Also        Applies To

Returns a CdbQueryDef object that is a copy of the QueryDef used to create the CdbRecordset object represented by the recordset placeholder (Microsoft Jet workspaces only).

Syntax

CdbQueryDefCopyQueryDef(VOID);

Remarks

You can use the CopyQueryDef method to create a new CdbQueryDef that is a duplicate of the CdbQueryDef used to create the CdbRecordset.

If a CdbQueryDef wasn't used to create this CdbRecordset, an error occurs. You must first open a CdbRecordset with the OpenRecordset method before using the CopyQueryDef method.

This method is useful when you create a CdbRecordset object from a CdbQueryDef, and pass the CdbRecordset to a function, and the function must re-create the SQL equivalent of the query, for example, to modify it in some way.

Usage

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

CdbDBEngine      dben;
CdbRecordset       rst;
CdbDatabase      dbs;
CdbQueryDef      qd;
CString         strSQL = _T("SELECT * FROM PARTS");
...
dbs = dben.OpenDatabase(_T("Northwind.mdb"));
   // Get a recordset based on a query.
rst = dbs.OpenRecordset(strSQL);
   // Get a copy of the query that built the recordset.
qd = rst.CopyQueryDef();     // Copy the queryDef