Hello! Prompt, please, why HasChanges (at DataSet) produces false after Merge of two tables? In the case when the data is replaced by the key, and in theory, the DataRowState change should work. On MSDN they write that it is necessary to set false in the preserveChanges parameter - it doesn't help
Here is a small example:
var ds = new DataSet(); var dt1 = new DataTable(); dt1.Columns.Add("id", typeof (int)); dt1.Columns.Add("name", typeof (string)); dt1.PrimaryKey = new[] {dt1.Columns["id"]}; dt1.Rows.Add(1, "name1"); dt1.Rows.Add(2, "name2"); ds.Tables.Add(dt1); ds.AcceptChanges(); var dt2 = new DataTable(); dt2.Columns.Add("id", typeof(int)); dt2.Columns.Add("name", typeof(string)); dt2.PrimaryKey = new[] { dt2.Columns["id"] }; dt2.Rows.Add(1, "name100"); dt2.Rows.Add(2, "name200"); dt2.AcceptChanges(); dt1.Merge(dt2, false); Console.WriteLine(ds.HasChanges()); Console.ReadKey();
false
means NOT to save changes. Settrue
. - Alexander Petrov