ACCESS 2000 데이터베이스 에 있 는 모든 표 의 이름 가 져 오기

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: %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 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);}(출처:풍 섬 망 학원)

좋은 웹페이지 즐겨찾기