Employee Details Example Program in VC++

//Note : you should need existing table named as  "employee"

#include<afxwin.h>
#include"resource.h"
#include <afxdb.h> 

class Dialog : public CDialog {
public:

   CRecordset rs;
   CString Name;
   int Data[6];
   int Index;
   CDBVariant Object;

   void DoDataExchange(CDataExchange* pDX) {
      CDialog::DoDataExchange(pDX);
      DDX_Text(pDX, IDC_EDIT1, Name);
      DDX_Text(pDX, IDC_EDIT2, Data[0]);
      DDX_Text(pDX, IDC_EDIT3, Data[1]);
      DDX_Text(pDX, IDC_EDIT4, Data[2]);
      DDX_Text(pDX, IDC_EDIT5, Data[3]);
      DDX_Text(pDX, IDC_EDIT6, Data[4]);
      DDX_Text(pDX, IDC_EDIT7, Data[5]);
   }

   Dialog(int n) : CDialog(n) {

      rs.Open(CRecordset::dynaset, _T("SELECT * FROM employee"));
      rs.MoveFirst();
      FetchRecord();
   }

   void FetchRecord() {
      Index = 0;
      rs.GetFieldValue(Index, Name);
      Index = 1;
      rs.GetFieldValue(Index, Object, SQL_C_SSHORT);
      Data[0] = Object.m_iVal;
      Index = 2;
      rs.GetFieldValue(Index, Object, SQL_C_SSHORT);
      Data[1] = Object.m_iVal;
      Index = 3;
      rs.GetFieldValue(Index, Object, SQL_C_SSHORT);
      Data[2] = Object.m_iVal;
      Index = 4;
      rs.GetFieldValue(Index, Object, SQL_C_SSHORT);
      Data[3] = Object.m_iVal;
      Index = 5;
      rs.GetFieldValue(Index, Object, SQL_C_SSHORT);
      Data[4] = Object.m_iVal;

      Data[5] = (Data[1] + Data[2] + Data[3] - Data[4]);
   }

   void FirstRecord() {
      rs.MoveFirst();
      FetchRecord();
      UpdateData(FALSE);
   }

   void NextRecord() {
      rs.MoveNext();
      if (!rs.IsEOF()) {
         FetchRecord();
         UpdateData(FALSE);
      } else {
         MessageBox("This Is Last Record");
         rs.MoveLast();
      }
   }

   void PrevRecord() {

      rs.MovePrev();
      if (!rs.IsBOF()) {
         FetchRecord();
         UpdateData(FALSE);
      } else {
         MessageBox("This Is First Record");
         rs.MoveFirst();
      }
   }

   void LastRecord() {
      rs.MoveLast();
      FetchRecord();
      UpdateData(FALSE);
   }
   DECLARE_MESSAGE_MAP()
};

BEGIN_MESSAGE_MAP(Dialog, CDialog)
ON_COMMAND(1006, FirstRecord)
ON_COMMAND(1007, LastRecord)
ON_COMMAND(1008, PrevRecord)
ON_COMMAND(1009, NextRecord)
END_MESSAGE_MAP()

class Frame : public CFrameWnd {
public:

   Frame() {
      Create(0, "Dialog", WS_OVERLAPPEDWINDOW, rectDefault, 0, MAKEINTRESOURCE(IDR_MENU1));
   }

   void OpenForm() {
      Dialog Run(IDD_DIALOG1);
      Run.DoModal();
   }
   DECLARE_MESSAGE_MAP()
};

BEGIN_MESSAGE_MAP(Frame, CFrameWnd)
ON_COMMAND(40001, OpenForm)
END_MESSAGE_MAP()


class Applet : public CWinApp {
public:

   int InitInstance() {
      Frame *Pointer = new Frame();
      Pointer->ShowWindow(3);
      m_pMainWnd = Pointer;
      return true;
   }
};

Applet Instance;