3

Has anybody come across ds.hasChanges() being false despite that the ds clearly has the changes while you check it at a breakpoint? I've been looking at it for quite a while and I can't see what is wrong...

// connectionstring and command has been set
DataSet ds = new DataSet();
BindingSource myBindingSource = new BindingSource();
SqlDataAdapter dataAdapter1 = new SqlDataAdapter();
dataAdapter1.Fill(ds, "Data");
myBindingSource.DataSource = ds.Tables["Data"];

// then changes made to the datatable on a windows form using bindingnavigator
ds.HasChanges(DataRowState.Modified); // is false

Now when I set a breakpoint after the row with HasChanges and use DataSet Visualizer I can see that the DataSet has in fact changed, but HasChanges still returns false.

I'm sure I'm missing the obvious... can anybody see what I'm doing wrong?

Cheers

Beska
  • 12,445
  • 14
  • 77
  • 112
G Berdal
  • 1,134
  • 3
  • 14
  • 28
  • What changes are made to the datatable - i.e. are rows definitely being updated, not added? Also, does dt.Tables["Data"].HasChanges return true? – AdaTheDev Jul 22 '09 at 14:03

2 Answers2

9

Try calling the EndCurrentEdit() on BindingContext first:

DataTable dt = ds.Tables["Data"];
this.BindingContext[dt].EndCurrentEdit();

if(ds.HasChanges(DataRowState.Modified))
{
  // do your stuff here
}

Also try calling the myBindingSource.EndEdit() that will push any un-commited data to the DataTable.

Vivek
  • 16,360
  • 5
  • 30
  • 37
0

The Windows Form isn't doing a .AcceptChanges() call on the DataSet is it?

Edit: Ok so not that. Next things, per my comment:
1) have records def been modified and not just added/deleted? What does DataSet.HasChanges() return?
2) what does GetChanges() return for the specific datable within the dataset?

AdaTheDev
  • 142,592
  • 28
  • 206
  • 200
  • 1. Records have been updated not deleted or added 2. returns false 3. there is no hasChanges for datatables, but if you mean getchanges that returns null as well – G Berdal Jul 22 '09 at 14:14