Can-Ann

I use a datatable, adapter and bindingsource to maintain records in an Access DB.

I would like to be able to check the event form_leaving that all updates have been done.

Can anyone show me how to do this, thanks in advance.



Re: Windows Forms Data Controls and Databinding Form Leaving - check all update done

Ken Tucker

In the form closing event I would use DataTable.GetChanges. It will return all records that have been changed since the datatable was loaded or acceptchanges was called. If there are any records returned you know there is unsaved data






Re: Windows Forms Data Controls and Databinding Form Leaving - check all update done

Can-Ann

I am not sure if this is correct. But it seems to work only if I move from one record to another, If I change a fields and move from that field then close - this does not occur.

Code Snippet

DataTable dtChanges = dtEmployee.GetChanges();

if (dtChanges != null)

{

DialogResult drResult = MessageBox.Show("Updates have been made - do you wish to save these changes ", "Data Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

if (drResult == DialogResult.Yes)

{

this.doSave();

}

}





Re: Windows Forms Data Controls and Databinding Form Leaving - check all update done

BabyFace Jay

Hi, I encountered this problem too and I solved by a Hack...Focus any button and DataTable get the changes. But of cuz I know there is a better way to do it but I am running out of time haha.... hope it helps you for now. find a better solution remember to post it here!

Code Snippet

this.button1.Focus(); // Added Code

DataTable dtChanges = dtEmployee.GetChanges();

if (dtChanges != null)

{

DialogResult drResult = MessageBox.Show("Updates have been made - do you wish to save these changes ", "Data Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

if (drResult == DialogResult.Yes)

{

this.doSave();

}

}





Re: Windows Forms Data Controls and Databinding Form Leaving - check all update done

Can-Ann

Found the correct answer :

You need to

Validate();