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

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
 
G

Guest

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
 
J

Jon Skeet [C# MVP]

Try this

ds1.AcceptChanges();
if (this.ds1.HasChanges())

If you've called AcceptChanges, then HasChanges is always going to be
false, isn't it?
 
S

Sijin Joseph

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top