4,011
社区成员
发帖
与我相关
我的任务
分享
#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("制定的表存在");
}
TablesPtr pTables = pCatalog->GetTables();
_Table* pTable = NULL;
pTables->get_Item(CComVariant(_T("Table Name")), &pTable);
TablesPtr pTables = NULL;
pTables =pCatalog->GetTables(); //看这行单步过后,pTables的值是否为NULL
#import "c:\program files\common files\system\ado\msadox.dll"
using namespace ADOX;
#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);
TablesPtr pTables = pCatalog->GetTables();
_Table* pTable = NULL;
if (pTables->get_Item(CComVariant(_T("Table Name")), &pTable) == S_OK)
{
// OK 指定的表存在。
}
#import "c:\program files\common files\system\ado\msadox.dll"
using namespace ADOX;
_CatalogPtr pCatalog;
pCatalog.CreateInstance(__uuidof(Catalog));
pCatalog->Create(CComBSTR(szConnStr));
//得到了Catalog对象就可以操作它里面的子对象(Groups, Procedures, Tables, Views, Users)等,例如要检查某个表是否已经存在 :
TablesPtr pTables = pCatalog->GetTables();
_Table* pTable = NULL;
if (pTables->get_Item(CComVariant(_T("Table Name")), &pTable) == S_OK)
{ // OK 指定的表存在。
//do something
}