JavaScript EditorDhtml editor     Free javascript download 

Main Page

The following example shows a quick and easy database access that does not involve commands. The following consumer code, in an ATL project, retrieves records from a table called Artists in a Microsoft Access database using the Microsoft OLE DB Provider for ODBC. The code creates a CTable table object with an accessor based on the user record class CArtists. It opens a connection, opens a session on the connection, and opens the table on the session.

В CopyCode imageCopy Code
#include <atldbcli.h>

CDataSource connection;
CSession session;
CTable<CAccessor<CArtists> > artists;

// Open the connection, session, and table, specifying authentication 
// using Windows NT integrated security. Hard-coding a password is a major
// security weakness.
connection.Open(CLSID_MSDASQL, "NWind", NULL, NULL, 
artists.Open(session, "Artists");
// Get data from the rowset
while (artists.MoveNext() == S_OK)
   cout << artists.m_szFirstName;
   cout << artists.m_szLastName;

The user record, CArtists, looks like this:

В CopyCode imageCopy Code
class CArtists
// Data Elements
   CHAR m_szFirstName[20];
   CHAR m_szLastName[30];
   short m_nAge;
// Column binding map
   COLUMN_ENTRY(1, m_szFirstName)
   COLUMN_ENTRY(2, m_szLastName)
   COLUMN_ENTRY(3, m_nAge)

Expand imageSee Also

JavaScript EditorDhtml editor     Free javascript download