ACCESS 2000データベースの全テーブルの名前を取得します。


void OpenSchemaX(TCHAR*Table Name){HRESULT hr=S_OK;:CoInitialize(NULL)//CommIADORecordBinding*picRs=NULLを初期化します。Recordset Ptr pRstSchema(「ADODB.Recordset」);Connection Ptr pConnection(「ADODB.Connection」);pConnection->Connection String=Table Name;pConnection->Provider=「Microsoft.Jett.OLED.4.0」try{pConnection->Open(pConnection->Connection String,""","",",adModeUniknown);pRstSchema->Query Interfaceuuidof(IADORecordBinding)、(LPVOID*)&picRs)pRstSchema=pConnection->Open Schema(adSchemaTables)//列挙表の名称処理while(!(pRstSchema->EndOfFile){CString strable Type;bstrtテーブルname=pRstSchema->Fields->GetItem("TABLE_"NAME"->Value;//表の名前を取得しますbstrtテーブルtype=pRstSchema->Fields->GetItem("TABLE_"TYPE"->>Value;//表のタイプを取得するためのstrebleType.Format("%s",(LPCSTR)テーブルテーブルの種類を取得します。タイプif(lstrcmp(streTable Type),_T(「TABLE」){m_strists.AddString(LPCSTR)テーブル_name)///表の名前を追加します。Clearn up object s before ext.pRstSchema->Close()pConnection->Close();catchcomerror&e){//Notify the user of errors if any.//Pass a connection pointer accessed from the Connection.PrintProvider Error(pConnection);PrintCommerror(e);CoUniitialize();void PrintProvider ErrorConnection Ptr pConnection){Err Ptr pErr=NULL}if((pConnection->Errors->Count)>>0){long nCount=pConnection->Errors->Count;/Collection ranges from 0 to nCount-1.for(long i=0)iErrers->GetItem(i);CString strerrerstrerror.Format("Errr number:%x\\t%s",pErr->Number,pErr->>Description);AfxMessage Box(sterror);}void PrintCommerror(u)comerror&e){u}bstrt bstr Source(e.Source);bstrt bstr Description(e.Description)//Print COM errors.CString strerrer;strerrror.Format("Error number:Description=%s\\tCode meaning=%s")、bstrectDescription、e.Error Message();AfxMessage Box(sterror);呼び出し方法:CString strefileName。TCHAR FileName[MAX_]PATH;;TCHAR bigBuff[2048]=_T(")////maximum common dialog buffer sizTCHARR szFilter[]=uT("Text Files(*.mdb)*.mdb𞓜All Files(*.*)|*")CFileDialog dll(TRUE、NULL、NULL、OFN_HIDEREADONLY OFN_ALLOWMUSLTIELECT,szFilter)//Modify OPEN FILENAME members directly to point to bigBuffdle.m_off.lpstFile=bigBff;dlt.m_off.nMaxFile=sizeof(bigBff)if(IDOK==dlt.domodal){strefileName=dlt.GetPathName();lstrcpy(FileName、strefileName)OpenSchemaX(FileName)=(出所:風閃ネット学院)