SourceField and SourceTable Properties Example (VC++)

This example creates a Recordset object using an SQL statement that creates aliases for fields in two different tables in the database. The example then prints the name of the field, the original table, and the original field.

CdbDBEngine      dbeng;
CdbDatabase      dbsNorthwind;
CdbRecordset      rstEmployCustID;
CdbField         fldEnum;
int            i;

// open database
dbsNorthwind = dbeng.OpenDatabase(_T("Northwind.mdb"));

rstEmployCustID = dbsNorthwind.OpenRecordset(_T("SELECT   EmployeeID 
   as EmpID, CustormerID as CustID FROM Employees, Customers;"));

for (i=0;i<rstEmployCustID.Fields.GetCount();i++)
   {
   fldEnum = rstEmployCustID.Fields.Item(i);
   // print field name
   printf("%s",fldEnum.GetName());
   // print original table name
   printf("%s",fldEnum.GetSourceTable());
   // print original field name
   printf("%s", fldEnum.GetSourceField());
   }

rstEmployCustID.Close();
dbsNorthwind.Close();