If I understand your question correctly, your DataTables have the same Column-schema and you want to get those rows that they do not have in common.
- Your current code intersects the rows of the DataTables, returning those rows that the DataTables have
in common. Instead you have to union the rows that that are missing from one table with those missing from the other.
- To copy DataRows to a new DataTable, the destination DataTable has to have the same Column-schema and you have to make a copy of the DataRow because you can't add a DataRow to a DataTable if it already belongs to another DataTable.
This will work for you:
var dt1Rows = dt1.AsEnumerable();
var dt2Rows = dt2.AsEnumerable();
var comparer = DataRowComparer.Default;
var diffRows = dt1Rows.Except(dt2Rows, comparer).Union(dt2Rows.Except(dt1Rows, comparer));
DataTable dt3 = dt1.Clone();
foreach (DataRow diffRow in diffRows)
{
DataRow rowCopy = dt3.NewRow();
rowCopy.ItemArray = diffRow.ItemArray;
dt3.Rows.Add(rowCopy);
}