I am trying to compare two datatables and capture the difference third datatable.
DataTable one = new DataTable();
one.Columns.Add("ID");
one.Columns.Add("PCT");
one.Rows.Add("1", "0.1");
one.Rows.Add("2", "0.2");
one.Rows.Add("3", "0.3");
gvone.DataSource = one;
gvone.DataBind();
DataTable two = new DataTable();
two.Columns.Add("ID");
two.Columns.Add("PCT");
two.Columns.Add("OldPCT");
two.Rows.Add("1", "0.0", "0");
two.Rows.Add("2", "0.1", "0");
two.Rows.Add("3", "0.9", "0");
two.Columns.Remove("OldPCT");
gvtwo.DataSource = two;
gvtwo.DataBind();
DataTable dt3 = two.AsEnumerable().Except(one.AsEnumerable()).CopyToDataTable();
var diffName = two.AsEnumerable().Select(r => r.Field<string>("PCT")).Except(one.AsEnumerable().Select(r => r.Field<string>("PCT")));
if (diffName.Any())
{
DataTable Table3 = (from row in two.AsEnumerable()
join name in diffName
on row.Field<string>("PCT") equals name
select row).CopyToDataTable();
}
Now my result in table 3 should be all rows in datatable two. since there is a mismatch in values. But it return only 1st and last row of datatable two. But I need to get all rows of table 2. How can I order the rows and compare.