资源描述:
《获取access2000数据库中所有表的名称》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、获取ACCESS2000数据库中所有表的名称>>教育资源库voidOpenSchemaX(TCHAR*TableName){HRESULThr=S_OK; ::CoInitialize(NULL);//初始化 IADORecordBinding*picRs=NULL; _RecordsetPtrpRstSchema(ADODB.Recordset);_ConnectionPtrpConnection(ADODB.Connection); pConnection->ConnectionString=Table
2、Name;pConnection->Provider=Microsoft.Jet.OLEDB.4.0; try{pConnection->Open(pConnection->ConnectionString,,,adModeUnknoa->QueryInterface(__uuidof(IADORecordBinding),(LPVOID*)picRs); pRstSchema=pConnection->OpenSchema(adSchemaTables);//枚举表的名称处理 a-&
3、gt;EndOfFile)){CStringstrTableType; _bstr_ttable_name=pRstSchema->Fields->GetItem(TABLE_NAME)->Value;//获取表的名称 _bstr_ttable_type=pRstSchema->Fields->GetItem(TABLE_TYPE)->Value;//获取表的类型 strTableType.Format(%s,(LPCSTR)table_type); if(!lstrcmp(s
4、trTableType,_T(TABLE))){m_strList.AddString((LPCSTR)table_name);//添加表的名称} pRstSchema->MoveNext();}//Cleanupobjectsbeforeexit. pRstSchema->Close();pConnection->Close();} catch(__errore){//Notifytheuseroferrorsifany.//Passaconnectionpointeraccessedfromt
5、heConnection.PrintProviderError(pConnection);PrintError(e);}CoUninitialize();} voidPrintProviderError(_ConnectionPtrpConnection){ErrorPtrpErr=NULL; if((pConnection->Errors->Count)>0){longnCount=pConnection->Errors->Count;//Collectionrangesfrom0to
6、nCount-1.for(longi=0;i<nCount;i++){pErr=pConnection->Errors->GetItem(i);CStringstrError;strError.Format(Errornumber:%xt%s,pErr->Number,pErr->Description);AfxMessageBox(strError);}}} voidPrintError(__errore){_bstr_tbstrSource(e.Source());_bstr_tbst
7、rDescription(e.Description()); //Printerrors.CStringstrError;strError.Format(Errornumber:Description=%stCodemeaning=%s,(LPCSTR)bstrDescription,e.ErrorMessage());AfxMessageBox(strError);} 调用方法:CStringstrFileName;TCHARFileName[MAX_PATH];TCHARbigBuff[2048]=_T();//
8、maximummondialogbuffersizeTCHARszFilter[]=_T(TextFiles(*.mdb)
9、*.mdb
10、AllFiles(*.*)
11、*.*);CFileDialogdlg(TRUE,NULL,NULL,OFN_HIDEREADONLY
12、OFN_ALLOULTISELECT,szFilt