Procedure:
1. Run MFCAppWizard(exe)
Step 1: Choose single document
Step 2: Select Database View without file support option also click Data
source button and choose ODBC data source name(student registration)
and select Dynaset as the record type, then select the table(student)
2. Add controls to the form template.
3. Using class wizardMember variable tabAdd variable buttonchoose the ID corresponding to the edit box for each variable.
4. Add the following items to the IDR_MAINFRAME menu
- Add record, Clear fields, Delete record, Update record
5. Use class wizard to map the menu command id’s with the corresponding
command handlers.
ID_RECORD_ADD OnRecordAdd
ID_RECORD_CLEARFIELDS OnRecordClearfields
ID_RECORD_DELETE OnRecordDelete
ID_RECORD_UPADTE OnRecordUpdate
6. Edit the menu command handlers under View.cpp file
7. Build and test the application
SOURCE CODE:
void CEx31bView::OnRecordAdd()
{
m_pSet->AddNew();
UpdateData(TRUE);
if (m_pSet->CanUpdate())
{
m_pSet->Update();
}
if (!m_pSet->IsEOF())
{
m_pSet->MoveLast();
}
//m_pSet->Requery();
UpdateData(FALSE);
}
void CEx31bView::OnRecordClearFields()
{
m_pSet->SetFieldNull(NULL);
UpdateData(FALSE);
}
void CEx31bView::OnRecordDelete()
{
CRecordsetStatus status;
try
{
m_pSet->Delete();
}
catch(CDBException* e)
{
AfxMessageBox(e->m_strError);
e->Delete();
m_pSet->MoveFirst();
UpdateData(FALSE);
return;
}
m_pSet->GetStatus(status);
if (status.m_lCurrentRecord ==0)
{
m_pSet->MoveFirst();
}
else
{
m_pSet->MoveNext();
}
UpdateData(FALSE);
}
void CEx31bView::OnUpdateRecordDelete(CCmdUI* pCmdUI)
{
pCmdUI->Enable(!m_pSet->IsEOF());
}
void CEx31bView::OnRecordUpdate()
{
m_pSet->Edit();
UpdateData(TRUE);
if (m_pSet->CanUpdate())
{
m_pSet->Update();
}
}
void CEx31bView::OnUpdateRecordUpdate(CCmdUI* pCmdUI)
{
pCmdUI->Enable(!m_pSet->IsEOF());
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment