Using Multiple Accessors on a Rowset

This example uses multiple accessors to retrieve one set of data. An application might use multiple accessors to optimize data access. The rowset retrieves one block of data that can be used by multiple accessors. (The accessor is defined in OLE DB User Records.)

#include <atldbcli.h>

CDataSource connection;
CSession session;
CTable<CAccessor< CMultiArtists> > artists;
 
// Connect the database, session, and accessors
connection.Open(CLSID_MSDASQL, "NWind", "sa", "");
session.Open(connection);
artists.Open(session, "artists");
 
// Retrieve the data
while (artists.MoveNext() == S_OK)
{
   cout << artists.m_szFirstName;
   cout << artists.m_szLastName;
   artists.GetData(1);   // Retrieve data for other accessor
   cout << artists.m_nAge;
}

The user record looks like this:

class CMultiArtists
{
public:
// Data Elements
   CHAR m_szFirstName[20];
   CHAR m_szLastName[30];
   short m_nAge;
 
// output binding map
BEGIN_ACCESSOR_MAP(CMultiArtists, 2)
   BEGIN_ACCESSOR(0, true)
    COLUMN_ENTRY(1, m_szFirstName)
    COLUMN_ENTRY(2, m_szLastName)
   END_ACCESSOR(0)
   BEGIN_ACCESSOR(1, false) // not an auto accessor
    COLUMN_ENTRY(3, m_nAge)
   END_ACCESSOR()
END_ACCESSOR_MAP()
};

Back to Common OLE DB Consumer Scenarios (Examples)