获取ACCESS2000数据库中所有表的名称

2008-02-23 08:04:35来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

void OpenSchemaX(TCHAR *TableName) { HRESULT hr = S_OK; 中.国.站长站

::CoInitialize(NULL); //初始化Com 站长.站

IADORecordBinding *picRs = NULL; 中国.站.长站

_RecordsetPtr pRstSchema("ADODB.Recordset"); _ConnectionPtr pConnection("ADODB.Connection" ); ^com

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);//添加表的名称 } Www__com

pRstSchema->MoveNext(); } // Clean up objects before exit. ^com

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()); ~com

// 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); @com

if(IDOK == dlg.DoModal() ) { strFileName = dlg.GetPathName(); lstrcpy(FileName,strFileName); OpenSchemaX(FileName); }(出处:风闪网路学院) 中国站.长.站

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:给你的数据库文件减肥

下一篇:Access命令行参数