2008-09-22 68 views

回答

0

在OLEDB它可以作爲DBSCHEMA_TABLES進行訪問。以下C++代碼演示了從OLEDB提供程序檢索表信息:

#include <atldb.h> 
... 
     // Standard way of obtaining table node info. 
     CAccessorRowset<CDynamicAccessor, CBulkRowset> pRS; 
     pRS.SetRows(100); 

     CSchemaTables<CSession>* pBogus; 
     hr = session.CreateSchemaRowset(NULL, 0, NULL, IID_IRowset, 0, NULL, (IUnknown**)&pRS.m_spRowset, pBogus); 
     if (FAILED(hr)) 
      goto lblError; 

     hr = pRS.Bind(); 
     if (FAILED(hr)) 
      goto lblError; 

     hr = pRS.MoveFirst(); 
     if (FAILED(hr)) 
      goto lblError; 

     while (S_OK == hr) 
     { 
      wstring sTableSchema(pRS.GetWCharValue(L"TABLE_SCHEMA")); 
      wstring sTableName(pRS.GetWCharValue(L"TABLE_NAME")); 
      wstring sTableType(pRS.GetWCharValue(L"TABLE_TYPE")); 
      ... 

      hr = pRS.MoveNext(); 
     } 
     pRS.Close();