5

In SQL you can use

SELECT * FROM INFORMATION_SCHEMA.TABLES

etc to get information about the database structure. I need to know how to achieve the same thing for an Access database.

Michael Prewecki
  • 2,064
  • 4
  • 16
  • 28

2 Answers2

5

The equivalent operation can be accomplished using

OleDbConnection.GetOleDbSchemaTable() method.

see http://support.microsoft.com/kb/309488 for more information

Michael Prewecki
  • 2,064
  • 4
  • 16
  • 28
  • Seems like the link is dead now. Do you happen to have an alternative? Maybe [this](https://learn.microsoft.com/en-us/dotnet/api/system.data.oledb.oledbconnection.getoledbschematable?view=dotnet-plat-ext-5.0) could be a replacement? – Matt Oct 11 '21 at 14:59
1

In OLEDB it can be accessed as DBSCHEMA_TABLES. Following C++ code demonstrates the retrieval of the tables information from an OLEDB provider:

#include <atldb.h>
...
        // Standard way of obtaining table node info.
        CAccessorRowset<CDynamicAccessor, CBulkRowset> pRS;
        pRS.SetRows(100);

        CSchemaTables<CSession>* pBogus;
        hr = session.CreateSchemaRowset(NULL, 0, NULL, IID_IRowset, 0, NULL, (IUnknown**)&pRS.m_spRowset, pBogus);
        if (FAILED(hr))
            goto lblError;

        hr = pRS.Bind();
        if (FAILED(hr))
            goto lblError;

        hr = pRS.MoveFirst();
        if (FAILED(hr))
            goto lblError;

        while (S_OK == hr)
        {
            wstring sTableSchema(pRS.GetWCharValue(L"TABLE_SCHEMA"));
            wstring sTableName(pRS.GetWCharValue(L"TABLE_NAME"));
            wstring sTableType(pRS.GetWCharValue(L"TABLE_TYPE"));
            ...

            hr = pRS.MoveNext(); 
        }
        pRS.Close();
Terry
  • 310
  • 3
  • 9