Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

saving a database on application exit

Status
Not open for further replies.

davewelsh

Programmer
Jun 26, 2001
71
CA
Hi. I need help

Does anyone know how to make a database save when the user exits the app? I don't want the user to have to move to another record to save.
 
If you are using VC++ then serialize your data (in the Serialize function) and use SetModifiedFlag() to mark your document as dirty. This is done when you add or modify a variable in your program.

Steve
 
I'm not sure how to get it to work that way.

I started with an SDI Project from the MFC AppWizard and I chose my view class to de derived from CRecordView. The app will save automatically when the user moves through the record using the premade toolbar buttons or menu options, but it won't save the latest change if the user exits the program without moving throught the record first. I can make a button that saves when clicked by having it run the code:

void somefunction()
{
//check to see if the user created a new record
if (m_UpdateMode) //new record was created
{
UpdateData(TRUE);
if (m_pSet->CanUpdate())
m_pSet->Update();
m_pSet->Requery();
}

else //only edits of current records were made
{
if (m_pSet->CanUpdate())
{
m_pSet->Edit();
UpdateData(TRUE);
m_pSet->Update();
}
}

m_UpdateMode = FALSE;
UpdateData(FALSE);
}


Now if I could put this code in a place that always runs before the View Class is destroyed, I think I'd be set.
 
OK I guess that was dumb. The ON_WM_DESTROY message handler worked fine for calling the code before the app closed.
 
If you are using MFC, just override CWinApp::ExitInstance and put there all code for destruct/saving/closing handles/files/databases/connections... John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top