.NET DataSet.HasChanges incorrectly invalid

Does anyone encounter ds.hasChanges () as false, even though ds obviously has a change while you check it at a breakpoint? I looked at him for a long time, and I do not 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 a line with HasChanges and use the Dataizer Visualizer, I see that the DataSet has actually changed, but HasChanges still returns false.

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

Greetings

+3
source share
2 answers

Try calling EndCurrentEdit () first in the BindingContext:

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

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

myBindingSource.EndEdit(), DataTable.

+8

Windows .AcceptChanges() DataSet?

Edit: , . , :
1) , /? DataSet.HasChanges()?
2) GetChanges() datable ?

0

Source: https://habr.com/ru/post/1713233/


All Articles