獲取ACCESS2000數(shù)據(jù)庫(kù)中所有表的名稱_Access數(shù)據(jù)庫(kù)教程
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é)院)
- Access數(shù)據(jù)庫(kù)安全策略之ASP式
- 第N次被ACCESS的關(guān)鍵字涮
- Access中用Jet SQL語(yǔ)句刪除表關(guān)系
- Access報(bào)表打印如何自動(dòng)分頁(yè)
- Access完成累計(jì)余額的計(jì)算
- 搭建Access為主的Mdb數(shù)據(jù)庫(kù)
- 一句sql更新兩個(gè)表并可更新對(duì)應(yīng)的字段值具體實(shí)現(xiàn)
- MySQL查詢優(yōu)化:連接查詢排序limit(join、order by、limit語(yǔ)句)介紹
- 內(nèi)網(wǎng)ssh/mysql登錄緩慢的解決方法
- 使用準(zhǔn)則進(jìn)行條件查詢--1.4.從窗體中選擇查詢的條件
- 中文Access2000速成教程--1.1 使用“向?qū)А痹O(shè)計(jì)數(shù)據(jù)庫(kù)
- 中文Access2000速成教程--1.3 在“設(shè)計(jì)”視圖中設(shè)計(jì)表
Access數(shù)據(jù)庫(kù)教程Rss訂閱編程教程搜索
Access數(shù)據(jù)庫(kù)教程推薦
- 用 INNER JOIN語(yǔ)法聯(lián)接多個(gè)表建記錄集
- 淺議ACCESS統(tǒng)計(jì)不重復(fù)記錄個(gè)數(shù)問(wèn)題
- 用Access創(chuàng)建簡(jiǎn)單MIS管理系統(tǒng)
- 數(shù)據(jù)在Access與Office組件間自由流動(dòng)
- 解析ACCESS作為網(wǎng)站數(shù)據(jù)庫(kù)的弊端
- 解答Perl下應(yīng)當(dāng)如何連接Access數(shù)據(jù)庫(kù)
- Oracle與Access表之間的導(dǎo)入和導(dǎo)出實(shí)現(xiàn)
- 揭秘ADO連接Access的幾種規(guī)范做法
- Access 2007通過(guò)查詢來(lái)計(jì)算累計(jì)余額
- 使用Access提高企業(yè)管理器功能
猜你也喜歡看這些
- 揭秘如何在Access數(shù)據(jù)庫(kù)中使用SQL
- ASP顯示ACCESS數(shù)據(jù)庫(kù)的GIF圖象
- Access數(shù)據(jù)庫(kù)出現(xiàn)“無(wú)法保存;正被別的用戶鎖定”的原因
- Access的控件布局之控件大小
- 詳解如何遠(yuǎn)程調(diào)用Access數(shù)據(jù)庫(kù)
- 解讀access處理重復(fù)記錄的方法
- ADODB連接access是出現(xiàn) 80004005 錯(cuò)誤的解決方法
- 解析Access與Sql Server之ASP代碼比較
- 如何刪除Access數(shù)詞庫(kù)中的空記錄
- 巧用in關(guān)鍵字實(shí)現(xiàn)數(shù)據(jù)的批量刪除
- 相關(guān)鏈接:
- 教程說(shuō)明:
Access數(shù)據(jù)庫(kù)教程-獲取ACCESS2000數(shù)據(jù)庫(kù)中所有表的名稱
。