ADOX中判断表的存在!

来源:互联网 发布:python 正则 匹配一个 编辑:程序博客网 时间:2024/06/15 03:38

ADOX::TablesPtr m_pTable = m_pCatalog->GetTables(); 
    bool bExist=FALSE;
    long x = m_pCatalog->Tables->Count;
  for (int i=0;i<x;i++)
   {
   if (m_pCatalog->Tables->Item[(long)i]->Name == _bstr_t(_T("officers")))
    bExist = TRUE;
   }
   if(!bExist)
   {

        //do what you want to do.
       }

 

 

 

//下面的这段代码我没有实现!


#include <adoint.h>#include <adoctint.h>
#include
<comdef.h>
#include
<shwapi.h>
#pragma comment(lib, "comsupp.lib")
#pragma comment(lib, "shlwapi.lib")

CComPtr
<ADOCatalog>Catalog;
HRESULT hr
= Catalog.CoCreateInstance(L"ADOX.Catalog");
if (FAILED(hr))
{
throw _com_error(hr, NULL);
}

static const TCHAR szConnStr[] =
_T(
"Provider=Microsoft.Jet.OLEDB.4.0;")
_T(
"Data Source=C://TEST1.MDB;");

CComVariant varConn;
hr
= Catalog->Create(CComBSTR(szConnStr), &varConn);

CComPtr
<ADOTables>Tables   =   NULL;    
Catalog
->get_Tables(&Tables);    
CComPtr
<ADOTable>Table   =   NULL;    
Tables
->get_Item(CComVariant(_T("Table   Name")), &Table);

if(Table!=NULL)
{
//MessageBox("制定的表存在");
}

原创粉丝点击