Accessing a database from a dialog.
In an MDI created with MFC, with database support, the form is already given access to the database, and it's valus can be accessed through variable names (for example m_Name gives access to the Name field in the current record) How do I add this functionality to a dialog that is not part of my form?
property sheets with database access
Code:
//** prior to calling this function insure to create the recordset and open it
//** CDaoDatabase db;
//** db.Open( strFullPathAndFileName );
//** m_pSet = new CMyRecordset( &db )
//** m_pSet->Open();
void CTykeView::CreateTabControl()
{
pSheet = new CPropertySheet( "My Tab", this, 0);
pSheet->AddPage( &m_Page1 );
pSheet->AddPage( &m_Page2 );
pSheet->AddPage( &m_Page3 );
//***********************************
//** do this prior to creation
//** If you have mapped the RS to the pages
m_page1.SetRecordSetPointer( &m_pSet );
m_page2.SetRecordSetPointer( &m_pSet );
m_page3.SetRecordSetPointer( &m_pSet );
/*
where the function looks like this
for each of the property pages
CMyProPage1::SetRecordSetPointer(CMyRecordset* pSet)
{
m_pSet = pSet;
}
*/
pSheet->Create( this, WS_CHILD | WS_VISIBLE );
CRect r;
m_staticPlaceHolder.GetWindowRect( &r );
ScreenToClient( &r );
pSheet->SetWindowPos( pSheet, r.top, r.left, 0, 0, SWP_NOSIZE | SWP_NOZORDER );
return;
}
to access the pages remember to call pSheet->SetActivePage( n )....otherwise you will get some nasty assertion errors trying to access a non active page... by default the first page is active..
and don't forget that prior to editing a recordset you must set edit in the following steps
1. Move to the record
2. call m_pSet->Edit()
3. update the data through the dialog
4. call m_pSet->Update()
5. move to another record or close it...
or
1. m_pSet->AddNew()
2. Update the data m_pSet->m_Name = strName;...etc
3. m_pSet->AddNew()
oops on CDaoRecordset::Update()
correction on that
m_pSet->AddNew();
....assign values
m_pSet->Update();