void OpenSchemaX(TCHAR *TableName){HRESULT hr = S_OK;::CoInitialize(NULL); //初始化ComIADORecordBinding *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: %xt%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 = %stCode meaning = %s",(LPCSTR) bstrDescription, e.ErrorMessage());AfxMessageBox(strError);}调用方法:CString strFileName;TCHAR FileName[MAX_PATH];TCHAR bigBuff[] = _T(""); // maximum common dialog buffer sizeTCHAR 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 bigBuffdlg.m_ofn.lpstrFile = bigBuff;dlg.m_ofn.nMaxFile = sizeof(bigBuff);if(IDOK == dlg.DoModal() ){strFileName = dlg.GetPathName();lstrcpy(FileName,strFileName);OpenSchemaX(FileName);}(出处:风闪网路学院)
推荐整理分享获取ACCESS2000数据库中所有表的名称(access怎么提取数据),希望有所帮助,仅作参考,欢迎阅读内容。
![获取ACCESS2000数据库中所有表的名称(access怎么提取数据)](https://www.jiuchutong.com/image/20240129/1706494826.jpg)
文章相关热门搜索词:excel获取access数据,access怎么提取数据,access获取文件夹地址,access怎么提取数据,access怎么提取数据,access获取用户名,access 获取,access获取查询记录数,内容如对您有帮助,希望把文章链接给更多的朋友!
解决Access出现Microsoft JET Database Engine (0x)未指定的错误 MicrosoftJETDatabaseEngine(0x)未指定的错误,这个错误只有在使用Access数据库时才能出现出现以上问题,可以使用以下步骤进行解决问题:1、系统可能没有
中文Access速成教程--1.3 在“设计”视图中设计表 第三讲在设计视图中设计表为了能像在中文VisualFoxPro6使用表设计器那样在中文Access中设计表,需要通过设计视图来进行操作,其步骤如下所述。步
中文Access速成教程--1.4 使用“表向导”建立新表 第四讲使用表向导建立新表与中文VisualFoxPro6一样,在中文Access中也能使用表向导从各种各样预先定义好的表中选择字段,并建立新的表,可以使用