主頁(yè) > 知識(shí)庫(kù) > 獲取ACCESS2000數(shù)據(jù)庫(kù)中所有表的名稱

獲取ACCESS2000數(shù)據(jù)庫(kù)中所有表的名稱

熱門標(biāo)簽:機(jī)器人電話機(jī)創(chuàng)意繪畫 天音通信電話機(jī)器人 杭州400電話如何申請(qǐng)的 高德地圖標(biāo)注商家在哪 江西南昌百應(yīng)電話機(jī)器人 400電話從哪里申請(qǐng)濱州 隨州營(yíng)銷電話機(jī)器人怎么樣 400電話申請(qǐng)?jiān)趺纯?/a> hbuilder地圖標(biāo)注

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: %x\t%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 = %s\tCode meaning = %s",(LPCSTR) bstrDescription, e.ErrorMessage());
AfxMessageBox(strError);
}

調(diào)用方法:

CString strFileName;
TCHAR FileName[MAX_PATH];
TCHAR bigBuff[2048] = _T(""); // maximum common dialog buffer size
TCHAR szFilter[] = _T("Text Files (*.mdb)|*.mdb|All Files (*.*)|*.*
");
CFileDialog dlg(TRUE, NULL, NULL,
OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT, szFilter);

// Modify OPENFILENAME members directly to point to bigBuff
dlg.m_ofn.lpstrFile = bigBuff;
dlg.m_ofn.nMaxFile = sizeof(bigBuff);

if(IDOK == dlg.DoModal() )
{
strFileName = dlg.GetPathName();
lstrcpy(FileName,strFileName);
OpenSchemaX(FileName);
}(出處:風(fēng)閃網(wǎng)路學(xué)院)

標(biāo)簽:昆明 鶴崗 常德 招商 石嘴山 葫蘆島 保定 沈陽(yáng)

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《獲取ACCESS2000數(shù)據(jù)庫(kù)中所有表的名稱》,本文關(guān)鍵詞  獲取,ACCESS2000,數(shù)據(jù)庫(kù),中,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《獲取ACCESS2000數(shù)據(jù)庫(kù)中所有表的名稱》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于獲取ACCESS2000數(shù)據(jù)庫(kù)中所有表的名稱的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章