Enumerating Tables in a Catalog

< BACK  NEXT >
[oR]

Any collection in ADOXCE can be enumerated (or iterated, as it is also known) to obtain a list of all the objects in the collection. For example, you may want to obtain a list of all the tables in a catalog. Each collection has a "Count" property that contains the number of items in the collection, and an Item function that returns an interface pointer to one of the items.

In Listing 16.3, a TablesPtr tables collection interface is obtained from the _CatalogPtr interface using the GetTables method. The code then displays the number of tables and uses a "for" loop to get a _TablePtr interface for each of the tables in the collection. The Item function is passed the index of the table whose _TablePtr is to be obtained. This is passed as a VARIANT.

Listing 16.3 Listing tables in a catalog
 void Listing16_3() {   AdoXNS::_CatalogPtr  pCatalog;   AdoXNS::TablesPtr    pTables;   AdoXNS::_TablePtr    pTable;   if(!OpenCatalog(lpConnection, pCatalog))       return;   // get collection of tables   pTables = pCatalog->GetTables();   // List tables   cout   _T("Number of tables:")          pTables->Count  endl;   for(short i = 0; i < pTables->Count; i++)   {     _variant_t vtIndex(i);     pTable = pTables->Item[vtIndex];     cout   _T("Table:")   (LPTSTR)pTable->Name                              endl;   } } 

< BACK  NEXT >


Windows CE 3. 0 Application Programming
Windows CE 3.0: Application Programming (Prentice Hall Series on Microsoft Technologies)
ISBN: 0130255920
EAN: 2147483647
Year: 2002
Pages: 181

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net