如何用OLEDB方式获取当前ACCESS数据库中有多少个表!

taianmonkey 2003-12-10 07:06:30
如何用OLEDB方式获取当前ACCESS数据库中有多少个表!
...全文
48 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
taianmonkey 2004-02-03
  • 打赏
  • 举报
回复
void OpenSchemaX(TCHAR *TableName)
{
HRESULT hr = S_OK;

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_cbTeam.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);
}
}
taianmonkey 2003-12-14
  • 打赏
  • 举报
回复
已经解决!

1,649

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 非技术类
社区管理员
  • 非技术类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧