使用查看所有表名语句:
select name from MSysObjects where type=1 and flags=0
并不成功,用GetLastError();查看是没有权限问题:

网上有修改mdb权限的方法,不过我的Access和一小部分网友一样,找不到【工具】这一栏
后面找到另一种方式:
void GetTableLists(const CString &strPath)
{
_ConnectionPtr m_pConnection;
_RecordsetPtr m_pRecordset;
HRESULT hr;
CStringArray dbtables;
try
{
CoInitialize(NULL);
hr = m_pConnection.CreateInstance(__uuidof(Connection));
hr = m_pRecordset.CreateInstance(__uuidof(Recordset));
if (SUCCEEDED(hr))
{
CString strconnection;
strconnection.Format(_T("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s"), strPath);
//12.0驱动使用strconnection.Format(_T("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=%s"), strPath);
hr = m_pConnection->Open((_bstr_t)strconnection, "", "", adModeUnknown);
m_pRecordset = m_pConnection->OpenSchema(adSchemaTables);
while (!(m_pRecordset->adoEOF))
{
_bstr_t table_name = m_pRecordset->Fields->GetItem("TABLE_NAME")->Value;
_bstr_t table_type = m_pRecordset->Fields->GetItem("TABLE_TYPE")->Value;
if (strcmp(((LPCSTR)table_type), "TABLE") == 0)
{
CString table;
table.Format(table_name);
dbtables.Add(table);
}
m_pRecordset->MoveNext();
}
m_pRecordset->Close();
}
m_pConnection->Close();
m_pRecordset.Release();
m_pConnection.Release();
CoUninitialize();
}
catch (_com_error e)
{
::MessageBox(NULL, e.Description(), L"错误", MB_OK);
return _T("");
}
}
在尝试使用SQL语句`SELECT name FROM MSysObjects WHERE type=1 AND flags=0`获取Access数据库所有表名时,遇到权限不足的问题。尽管GetLastError()显示没有权限错误,但在Access中找不到工具菜单来修改权限。文章提到了一种替代方法来解决这个问题,参考自https://blog.csdn.net/itmes/article/details/5213087。

3841

被折叠的 条评论
为什么被折叠?



