国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > Access > 正文

獲取ACCESS2000數據庫中所有表的名稱

2024-09-07 19:05:16
字體:
來源:轉載
供稿:網友

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);

}

調用方法:

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);

}(出處:風閃網路學院)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 靖远县| 康马县| 白玉县| 古交市| 沁阳市| 丘北县| 太仓市| 边坝县| 清远市| 炎陵县| 福泉市| 通辽市| 神木县| 桐梓县| 天气| 澄迈县| 岫岩| 朔州市| 临清市| 简阳市| 鹤峰县| 镇巴县| 崇义县| 南和县| 清水县| 凯里市| 金溪县| 祁阳县| 吉安县| 雅江县| 灵寿县| 鄄城县| 鹤壁市| 临城县| 黄陵县| 天镇县| 沙雅县| 武鸣县| 伊金霍洛旗| 龙江县| 长汀县|