国产探花免费观看_亚洲丰满少妇自慰呻吟_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);

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 黎城县| 辽宁省| 南丰县| 教育| 小金县| 武安市| 金门县| 承德市| 丰原市| 娄烦县| 新巴尔虎左旗| 隆昌县| 安陆市| 望城县| 象山县| 汪清县| 东乌珠穆沁旗| 尚志市| 苗栗县| 庆云县| 宁河县| 三门峡市| 河津市| 湘阴县| 封开县| 奈曼旗| 永春县| 运城市| 武胜县| 红河县| 灵石县| 永年县| 吕梁市| 周至县| 隆子县| 恩施市| 江阴市| 鸡西市| 吴旗县| 芜湖市| 赫章县|