Hi.
I writed a method that takes two DataTable with same schema
and return a third DataTable that:
- insert new rows from "compare" DataTable
- delete rows contained in "source" and not in "compare" DataTable
- update rows from "compare"
--------------------------------------
public static DataTable GetMergedTable(DataTable source, DataTable compare)
{
DataTable ret = new DataTable();
ret.Merge(source);
ret.Merge(compare);
ret.AcceptChanges();
for (int i = 0; i < ret.Rows.Count; i++) {
DataRow row = ret.Rows[i];
bool sourceFound = source.Rows.Find(row["id"]) != null;
bool compareFound = compare.Rows.Find(row["id"]) != null;
//Row added
if ((!sourceFound) && (compareFound))
row.SetAdded();
//Row modified
if ((sourceFound) && (compareFound))
row.SetModified();
//Row deleted
if ((sourceFound) && (!compareFound))
row.Delete();
}
return ret;
}
--------------------------------------
When I execute an update with SqlDataAdapter.Update
rows are inserted and deleted correctly, but never updated.
What is the problem?
Thx! ;-)
Matteo Migliore.