DataSet.HasChanges() always returns false even though there are changes

  • Thread starter Thread starter mzam
  • Start date Start date
M

mzam

Hi All,

I have a set of textboxes bound to a typed dataset (ds1). This dataset
contains one table which contains only one record.

This is an example on how I do the binding for the textboxes:

txtDescription.DataBindings.Add(new Binding("Text", ds1.ShareClass,
"Name"));

When I am about to save the changes I call the ds1.HasChanges() method and
it always returns false even though I made changes in the bound textboxes.

if (this.ds1.HasChanges())
{
DSFund getChangesDS = new DSFund();
getChangesDS.Merge(ds1.GetChanges());
businessFacade.SaveFund(getChangesDS);
ds1.Merge(getChangesDS);
ds1.AcceptChanges();
}

Am I missing a line of code before calling the HasChanges()?

Thanks for your help,

mZam
 
Try this

ds1.AcceptChanges();
if (this.ds1.HasChanges())
{
DSFund getChangesDS = new DSFund();
getChangesDS.Merge(ds1.GetChanges());
businessFacade.SaveFund(getChangesDS);
ds1.Merge(getChangesDS);
ds1.AcceptChanges();
}


Bye.


Thomas LEBRUN
 
Are you sure the changes are getting commited back to the datatable. You
will need to tab out or move focus away from the text box for the value
to be propogated to the datatable. You can add an eventhandler for the
dtatable.RowChanging event and check if a row actually does get changed
ever.

Also make sure that you are not calling AcceptChanges() anywhere in your
code before you commit the changes to the database.

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
 
Back
Top