获取ACCESS2000数据库中所有表的名称
数据库 获取 所有 名称 Access2000
2023-06-13 09:13:46 时间
voidOpenSchemaX(TCHAR*TableName)
{
HRESULThr=S_OK;
::CoInitialize(NULL);//初始化Com
IADORecordBinding*picRs=NULL;
_RecordsetPtrpRstSchema("ADODB.Recordset");
_ConnectionPtrpConnection("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))
{
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(strTableType,_T("TABLE")))
{
m_strList.AddString((LPCSTR)table_name);//添加表的名称
}
pRstSchema->MoveNext();
}
//Cleanupobjectsbeforeexit.
pRstSchema->Close();
pConnection->Close();
}
catch(_com_error&e)
{
//Notifytheuseroferrorsifany.
//PassaconnectionpointeraccessedfromtheConnection.
PrintProviderError(pConnection);
PrintComError(e);
}
CoUninitialize();
}
voidPrintProviderError(_ConnectionPtrpConnection)
{
ErrorPtrpErr=NULL;
if((pConnection->Errors->Count)>0)
{
longnCount=pConnection->Errors->Count;
//Collectionrangesfrom0tonCount-1.
for(longi=0;i<nCount;i++)
{
pErr=pConnection->Errors->GetItem(i);
CStringstrError;
strError.Format("Errornumber:%x\t%s",pErr->Number,pErr->Description);
AfxMessageBox(strError);
}
}
}
voidPrintComError(_com_error&e)
{
_bstr_tbstrSource(e.Source());
_bstr_tbstrDescription(e.Description());
//PrintCOMerrors.
CStringstrError;
strError.Format("Errornumber:Description=%s\tCodemeaning=%s",(LPCSTR)bstrDescription,e.ErrorMessage());
AfxMessageBox(strError);
}
调用方法:
CStringstrFileName;
TCHARFileName[MAX_PATH];
TCHARbigBuff[2048]=_T("");//maximumcommondialogbuffersize
TCHARszFilter[]=_T("TextFiles(*.mdb)|*.mdb|AllFiles(*.*)|*.*
");
CFileDialogdlg(TRUE,NULL,NULL,
OFN_HIDEREADONLY|OFN_ALLOWMULTISELECT,szFilter);
//ModifyOPENFILENAMEmembersdirectlytopointtobigBuff
dlg.m_ofn.lpstrFile=bigBuff;
dlg.m_ofn.nMaxFile=sizeof(bigBuff);
if(IDOK==dlg.DoModal())
{
strFileName=dlg.GetPathName();
lstrcpy(FileName,strFileName);
OpenSchemaX(FileName);
}(出处:风闪网路学院)
{
HRESULThr=S_OK;
::CoInitialize(NULL);//初始化Com
IADORecordBinding*picRs=NULL;
_RecordsetPtrpRstSchema("ADODB.Recordset");
_ConnectionPtrpConnection("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))
{
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(strTableType,_T("TABLE")))
{
m_strList.AddString((LPCSTR)table_name);//添加表的名称
}
pRstSchema->MoveNext();
}
//Cleanupobjectsbeforeexit.
pRstSchema->Close();
pConnection->Close();
}
catch(_com_error&e)
{
//Notifytheuseroferrorsifany.
//PassaconnectionpointeraccessedfromtheConnection.
PrintProviderError(pConnection);
PrintComError(e);
}
CoUninitialize();
}
voidPrintProviderError(_ConnectionPtrpConnection)
{
ErrorPtrpErr=NULL;
if((pConnection->Errors->Count)>0)
{
longnCount=pConnection->Errors->Count;
//Collectionrangesfrom0tonCount-1.
for(longi=0;i<nCount;i++)
{
pErr=pConnection->Errors->GetItem(i);
CStringstrError;
strError.Format("Errornumber:%x\t%s",pErr->Number,pErr->Description);
AfxMessageBox(strError);
}
}
}
voidPrintComError(_com_error&e)
{
_bstr_tbstrSource(e.Source());
_bstr_tbstrDescription(e.Description());
//PrintCOMerrors.
CStringstrError;
strError.Format("Errornumber:Description=%s\tCodemeaning=%s",(LPCSTR)bstrDescription,e.ErrorMessage());
AfxMessageBox(strError);
}
调用方法:
CStringstrFileName;
TCHARFileName[MAX_PATH];
TCHARbigBuff[2048]=_T("");//maximumcommondialogbuffersize
TCHARszFilter[]=_T("TextFiles(*.mdb)|*.mdb|AllFiles(*.*)|*.*
");
CFileDialogdlg(TRUE,NULL,NULL,
OFN_HIDEREADONLY|OFN_ALLOWMULTISELECT,szFilter);
//ModifyOPENFILENAMEmembersdirectlytopointtobigBuff
dlg.m_ofn.lpstrFile=bigBuff;
dlg.m_ofn.nMaxFile=sizeof(bigBuff);
if(IDOK==dlg.DoModal())
{
strFileName=dlg.GetPathName();
lstrcpy(FileName,strFileName);
OpenSchemaX(FileName);
}(出处:风闪网路学院)
相关文章
- 获取impala下所有的数据库建表语句
- VB使用ADO操作Access数据库的案例分享
- postgresql数据库如何查看连接数和状态查询的信息
- 通过系统数据库获取用户所有数据库中的视图、表、存储过程
- 随机获取oracle数据库中的任意一行数据(rownum)示例介绍
- oracle 查询之前的表数据详解数据库
- oracle时间的获取,前一天,上一个星期,上一个月详解数据库
- 获取MySQL系统当前时间详解数据库
- 『登录Oracle数据库服务器获取新知识』(登陆本地oracle)
- 解锁Oracle数据库之旅:登陆篇(oracle数据库登陆)
- 安装Oracle:获取数据库之旅(安装oracle)
- 利用Oracle进行数据库等于lt操作(oraclelt)
- 学习PostgreSQL数据库必备!观看高质量视频教程(postgresql视频)
- Oracle快照查询,轻松获取数据库信息。(oracle查看快照)
- 获取SQLServer数据库字段的长度(sqlserver取长度)
- 如何快速利用MSSQL获取所有数据库名称(mssql 获取所有库名)
- 数据库与Linux: 开启新的信息时代(数据库和linux)
- sql如何利用PLSQL实现Oracle数据库全库导出(oracle全库导出pl)
- 库C语言程序从Oracle数据库取数据的实现(c 获取oracle数据)
- 12c Oracle数据库介绍与应用(12c oracle介绍)
- Oracle数据库技术获取随机数(oracle中随机数获取)
- MySQL下载网站源代码获取高效数据库的代码文件(mysql下载网站源代码)
- 位数据库Oracle 64位与32位数据库的比较与选择(oracle64和32)
- 数据库记录的删除,delete好还是update好?
- 多种获取远程连接access数据库的方法
- .net实现oracle数据库中获取新插入数据的id的方法
- 通过系统数据库获取用户所有数据库中的视图、表、存储过程