游客:
注册
|
登录
|
帮助
网友俱乐部
»
数据库操作
»
ACCESS教程
» 获取Access2000数据库中所有表的名称
网友生活网
|
网友学堂
如何获得金币?
诚招斑竹
IP归属地查询 PR查询 收录查询 whois查询
免费超短2级域名,your.jpy.cc
火狐浏览器,网上冲浪更快更爽更惬意
注册亚洲交友中心,找个人来同居吧!
7CODE查杀恶意代码,守护您的电脑
‹‹ 上一主题
|
下一主题 ››
投票
交易
悬赏
活动
打印
|
推荐
|
订阅
|
收藏
标题: 获取Access2000数据库中所有表的名称
ljjk5
元帅
UID 46706
精华
1
积分 99426
帖子 49691
威望 554
金币 48489
热心 505
阅读权限 100
注册 2007-2-25
状态 离线
#1
使用道具
发表于 2007-11-23 17:56
资料
个人空间
主页
短消息
加为好友
获取Access2000数据库中所有表的名称
如何获取Access2000中所有表的名称,以下是实现功能的代码:
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[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);}
网友
ljjk5
签名 - 网友社区
===
[广告]
免费域名(Free Subdomain)
免费空间(Free hosting)
PR查询(Google Pagerank)
投票
交易
悬赏
活动
控制面板首页
编辑个人资料
积分交易
公众用户组
好友列表
个人空间管理
基本概况
流量统计
客户软件
发帖量记录
论坛排行
主题排行
发帖排行
积分排行
在线时间
管理团队
管理统计
当前时区 GMT+8, 现在时间是 2008-7-26 15:11
信产部ICP备案:
京ICP备05066424号
北京市公安局网监备案:1101050648号
Powered by
Discuz!
5.5.0
TOP
清除 Cookies
-
联系我们
-
网友俱乐部
-
Archiver
-
WAP