Tables, including the data they contain, can be dropped through the TablesPtr collection. In Listing 16.4 a catalog is opened and a TablesPtr interface pointer obtained. The name of the table to be dropped ("Customers") is set into a VARIANT containing a BSTR, and the TablesPtr interface function Delete is used to drop the table. Listing 16.4 Dropping a tablevoid Listing16_4() { AdoXNS::_CatalogPtr pCatalog; AdoXNS::TablesPtr pTables; AdoXNS::_TablePtr pTable; HRESULT hr; if(!OpenCatalog(lpConnection, pCatalog)) return; // get collection of tables pTables = pCatalog->GetTables(); // Specify table to drop _bstr_t bstrTable(_T("Customers")); _variant_t varTable(bstrTable); hr = pTables->Delete(varTable); if(FAILED(hr)) { cout _T("Could not drop table") endl; return; } cout _T("Table dropped") endl; }
|