Question

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.

Was it helpful?

Solution

The equivalent operation can be accomplished using

OleDbConnection.GetOleDbSchemaTable() method.

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

OTHER TIPS

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();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top