DAO database connection - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

DAO database connection

anton19822anton19822 Posts: 12Member
Hey...

Ive made a connection to an access 97 database and using dialog boxes am viewing the information in edit boxes.

I made an edit dialog to edit the details but when i edit it...it changes on the other dialog but doesnt save to the database so when u click prev then next it changes back to original.

Can somebody help and maybe show me where to put the code.

This is the original dialog

#include "stdafx.h"
#include "Anthony.h"

#include "AnthonySet.h"
#include "AnthonyDoc.h"
#include "AnthonyView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAnthonyView

IMPLEMENT_DYNCREATE(CAnthonyView, CDaoRecordView)

BEGIN_MESSAGE_MAP(CAnthonyView, CDaoRecordView)
//{{AFX_MSG_MAP(CAnthonyView)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CDaoRecordView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CDaoRecordView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CDaoRecordView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAnthonyView construction/destruction

CAnthonyView::CAnthonyView()
: CDaoRecordView(CAnthonyView::IDD)
{
//{{AFX_DATA_INIT(CAnthonyView)
m_pSet = NULL;
//}}AFX_DATA_INIT
// TODO: add construction code here

}

CAnthonyView::~CAnthonyView()
{
}

void CAnthonyView::DoDataExchange(CDataExchange* pDX)
{
CDaoRecordView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAnthonyView)
DDX_FieldText(pDX, IDC_EDIT1, m_pSet->m_Family_Name, m_pSet);
DDX_FieldText(pDX, IDC_EDIT2, m_pSet->m_First_Name, m_pSet);
DDX_FieldText(pDX, IDC_EDIT3, m_pSet->m_Reg_Number, m_pSet);
DDX_FieldText(pDX, IDC_EDIT4, m_pSet->m_Gender, m_pSet);
DDX_FieldCBString(pDX, IDC_COMBO1, m_pSet->m_Course, m_pSet);
//}}AFX_DATA_MAP
}

BOOL CAnthonyView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs

return CDaoRecordView::PreCreateWindow(cs);
}

void CAnthonyView::OnInitialUpdate()
{
m_pSet = &GetDocument()->m_anthonySet;
CDaoRecordView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();

}

/////////////////////////////////////////////////////////////////////////////
// CAnthonyView printing

BOOL CAnthonyView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}

void CAnthonyView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}

void CAnthonyView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CAnthonyView diagnostics

#ifdef _DEBUG
void CAnthonyView::AssertValid() const
{
CDaoRecordView::AssertValid();
}

void CAnthonyView::Dump(CDumpContext& dc) const
{
CDaoRecordView::Dump(dc);
}

CAnthonyDoc* CAnthonyView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CAnthonyDoc)));
return (CAnthonyDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CAnthonyView database support
CDaoRecordset* CAnthonyView::OnGetRecordset()
{
return m_pSet;
}


/////////////////////////////////////////////////////////////////////////////
// CAnthonyView message handlers

void CAnthonyView::OnButton1()
{
m_pSet->MoveNext();
m_pSet->m_Family_Name;
UpdateData(0);


}

void CAnthonyView::OnButton2()
{
m_pSet->MovePrev();
m_pSet->m_Family_Name;
UpdateData(0);

}

void CAnthonyView::OnButton3()
{
CAntdlg d;
UpdateData(1);
d.m_Family_Name = m_pSet->m_Family_Name;
d.m_First_Name = m_pSet->m_First_Name;
d.m_Registration_Number = m_pSet->m_Reg_Number;
d.m_Course = m_pSet->m_Course;
int ret = d.DoModal();
if(ret==1)
m_pSet->m_Family_Name = d.m_Family_Name;
m_pSet->m_First_Name = d.m_First_Name;
UpdateData(0);
}

and here is the edit dialog

#include "stdafx.h"
#include "Anthony.h"
#include "Antdlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAntdlg dialog


CAntdlg::CAntdlg(CWnd* pParent /*=NULL*/)
: CDialog(CAntdlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CAntdlg)
m_Family_Name = _T("");
m_First_Name = _T("");
m_Registration_Number = _T("");
m_Course = _T("");
//}}AFX_DATA_INIT
}


void CAntdlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAntdlg)
DDX_Text(pDX, IDC_EDIT1, m_Family_Name);
DDX_Text(pDX, IDC_EDIT2, m_First_Name);
DDX_Text(pDX, IDC_EDIT3, m_Registration_Number);
DDX_CBString(pDX, IDC_COMBO1, m_Course);
//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CAntdlg, CDialog)
//{{AFX_MSG_MAP(CAntdlg)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAntdlg message handlers

void CAntdlg::OnButton1()
{

}

void CAntdlg::OnRadio1()
{
// TODO: Add your control notification handler code here

}

void CAntdlg::OnChangeEdit1()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.

// TODO: Add your control notification handler code here

}

Comments

  • stoberstober Posts: 9,765Member ✭✭✭
    have you read the Microsoft Enroll tutorial? If not, you should because it shows you the information you need.
Sign In or Register to comment.