当前位置: 首页 > 图文教程 > 数据库 > Access > 获取ACCESS2000数据库中所有表的名称

Access
长期使用中型Access数据库的一点经验与缺点
加密你的Access数据库asp打开方法
access下如何恢复已经删除的记录;如何恢复已经删除的表、窗体等等对象
恢复从 Access 2000、 Access 2002 或 Access 2003 中数据库删除表的方法
ACCESS的参数化查询,附VBSCRIPT(ASP)和C#(ASP.NET)函数
access的备注字段限制64K
根据IP跳转到用户所在城市的实现步骤
Access出现"所有记录中均未找到搜索关键字"的错误解决
Access数据库出现“无法保存;正被别的用户锁定”的原因
ACCESS 调用后台存储过程的实现方法
Access 模糊参数 分页查询
Access转Sql Server问题 实例说明
Access 执行SQL的方法
access 数据库自启动困难解决方法
ADODB连接access是出现 80004005 错误的解决方法
处理加了密码的MDB文件
ACCESS数据访问页配置实例
Word与Access数据交流技巧
ACCESS作为网站数据库的弊端
Oracle与Access表之间的导入和导出实现

Access 中的 获取ACCESS2000数据库中所有表的名称


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 62 ::
收藏到网摘: n/a


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);
}(出处:风闪网路学院)