linux数据库表代码,简单代码获取Access2000数据库中所有表的名称

void OpenSchemaX(TCHAR *TableName)

{

HRESULT hr = S_OK;

::CoInitialize(NULL); //初始化Com

IADORecordBinding *picRs = NULL;

_RecordsetPtr pRstSchema("ADODB.Recordset");

_ConnectionPtr pConnection("ADODB.Connection" );

pConnection->ConnectionString = TableName;

pConnection->Provider = "Microsoft.Jet.OLEDB.4.0";

try

{

pConnection->Open(pConnection->ConnectionString, "", "",

adModeUnknown);

pRstSchema->QueryInterface(

__uuidof(IADORecordBinding), (LPVOID*)&picRs);

pRstSchema = pConnection->OpenSchema(adSchemaTables);

//枚举表的名称处理

while(!(pRstSchema->EndOfFile))

{

CString strTableType;

_bstr_t table_name = pRstSchema->Fields->

GetItem("TABLE_NAME")->Value;//获取表的名称

_bstr_t table_type = pRstSchema->Fields->

GetItem("TABLE_TYPE")->Value;//获取表的类型

strTableType.Format("%s",(LPCSTR) table_type);

if(!lstrcmp(strTableType,_T("TABLE")))

{

m_strList.AddString((LPCSTR) table_name);

//添加表的名称

}

pRstSchema->MoveNext();

}

// Clean up objects before exit.

pRstSchema->Close();

pConnection->Close();

}

catch (_com_error &e)

{

// Notify the user of errors if any.

// Pass a connection pointer accessed from the Connection.

PrintProviderError(pConnection);

PrintComError(e);

}

CoUninitialize();

}

void PrintProviderError(_ConnectionPtr pConnection)

{

ErrorPtr pErr = NULL;

if( (pConnection->Errors->Count) > 0)

{

long nCount = pConnection->Errors->Count;

// Collection ranges from 0 to nCount -1.

for(long i = 0;i < nCount;i++)

{

pErr = pConnection->Errors->GetItem(i);

CString strError;

strError.Format("Error number: %xt%s", pErr->Number, pErr->Description);

AfxMessageBox(strError);

}

}

}

void PrintComError(_com_error &e)

{

_bstr_t bstrSource(e.Source());

_bstr_t bstrDescription(e.Description());

// Print COM errors.

CString strError;

strError.Format("Error number:

Description = %stCode meaning = %s",(LPCSTR)

bstrDescription, e.ErrorMessage());

AfxMessageBox(strError);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值