0

I have one DataSet object which contains two DataTable objects. Both DataTable have the same structure but first of them is older then second. Second DataTable contains part of the older DataTable object rows and some new rows. I need to know which rows has been added to "newer" DataTable comparing to the older.

I thought about method which takes two parameters (older and newer DataTable) and returns DataRow[] collection containing added rows to newer DataTable :

private DataRow[] GetNewDataRows(DataTable oldDT, DataTable newDT)
    {
        // code
    }

I don't know how to achieve that. Can anyone help ? Regards

Dear Deer
  • 515
  • 1
  • 11
  • 29
  • 4
    http://stackoverflow.com/questions/15713243/compare-two-datatables-and-select-the-rows-that-are-not-present-in-second-table – Dhaval Asodariya Feb 19 '16 at 10:23
  • Take the max id or creationdate from old table. Then select all rows in the new tables with an id > that id. – Carra Feb 19 '16 at 11:00

1 Answers1

0

Hope you are looking for some thing like check col value

var dtData1 = datatable1.AsEnumerable().Select(a => new { ColValue = a["SomeCol"].ToString() });
var dtData2 = datatable2.AsEnumerable().Select(a => new { ColValue = a["SomeCol"].ToString() });

var exceptXY = dtData1.Except(dtData2);

DataTable dtMisMatch = (from a in datatable1.AsEnumerable() 
                       join xy in exceptXY on a["SomeCol"].ToString() equals ab.ColValue select a).CopyToDataTable();

I may not understood correctly but thought this help you.

LifeOfPi
  • 625
  • 5
  • 19