QueryDef Object, QueryDefs Collection Example (VC++)

This example creates a new QueryDef object and appends it to the QueryDefs collection in the current database. Then the example enumerates all the QueryDef objects in the database and all the properties of the new QueryDef. See the methods and properties listed in the QueryDef summary topic for additional examples.

CdbDBEngine   dbeng;
CdbDatabase   db;
CdbQueryDef   qdfTest;
COleVariant   var("This is a user-defined property.",
      VC_BSTRT);
int         i;

// Open the database.
db = dbeng.OpenDatabase(_T("Northwind.mdb"));

// Create a query definition.
qdfTest = db.CreateQueryDef(_T("This is a test"));

// Enumerate QueryDef objects.
for (i = 0; i < db.QueryDefs.GetCount(); i++)
{
   printf("%s\n", db.QueryDefs[i].GetName());
}

// Enumerate built-in properties of qdfTest.
printf("qdfTest.Name: %s\n", qdfTest.GetName());
printf("qdfTest.DateCreated: %s\n", qdfTest.GetDateCreated().Format());
printf("qdfTest.LastUpdated: %s\n", qdfTest.GetLastUpdated().Format());
printf("qdfTest.SQL: %s\n", qdfTest.GetSQL());
printf("qdfTest.ODBCTimeout: %d\n", qdfTest.GetODBCTimeout());
printf("qdfTest.Updatable: %d\n", qdfTest.GetUpdatable());
printf("qdfTest.Type: %d\n", qdfTest.GetType());
printf("qdfTest.Connect: %s\n", qdfTest.GetConnect());
printf("qdfTest.ReturnsRecords: %d\n", qdfTest.GetReturnsRecords());
   
// Delete the query definition.
db.QueryDefs.Delete(_T("This is a test"));