void OpenSchemaX(TCHAR *TableName)
{
HRESULT hr = S_OK;
::CoInitialize(NULL); //初始化Com
IADORecordBinding *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 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);
if(IDOK == dlg.DoModal() )
{
strFileName = dlg.GetPathName();
lstrcpy(FileName,strFileName);
OpenSchemaX(FileName);
}(出处:风闪网路学院)
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
暂无评论...
更新日志
2024年11月22日
2024年11月22日
- 李俊广VS许岚岚《秋蝉》[低速原抓WAV+CUE]
- 证声音乐图书馆《毕业季·青春爵士》[FLAC/分轨][265.35MB]
- 证声音乐图书馆《爵士嘉年华 Big Band Swing》[320K/MP3][62.44MB]
- 证声音乐图书馆《爵士嘉年华 Big Band Swing》[FLAC/分轨][239.3MB]
- 中国民歌宝典《民歌精粹经典珍藏》12CD[WAV]
- 阿姆斯特丹小交响乐团演奏《室内交响曲》SACD-WAV
- Parijat-BuddhaGarden《佛陀花园》[WAV+CUE]
- 证声音乐图书馆《巴莎诺瓦 惬意咖啡馆》[320K/MP3][220.56MB]
- 证声音乐图书馆《巴莎诺瓦 惬意咖啡馆》[FLAC/分轨][220.56MB]
- 群星《狂潮》夜店中文爆嗨重低音 黑胶碟2CD[低速原抓WAV+CUE]
- TraditionalMusicEnsembleofTheBNMA-BuddhistMusicoftheMingDynasty(JVC-Japan)[FLAC]
- [中国唱片]中央乐团交响乐队《绝烧HIFI典范》[WAV+CUE]
- 群星《2024好听新歌41》AI调整音效【WAV分轨】
- 张学友《吻别》MQA-UHQCD 日本压碟[原抓WAV+CUE][1G]
- 许嵩《寻宝游戏》[WAV+CUE][951M]