c# - Comparing two DataTables to determine if it is modified -


i have 2 datatables:

datatable original; datatable modified;

the 2 tables has same number of rows , columns , datas same.

i want modified datable determine each row compare original datatable . if row modified datatable not equal row of original datatable row's .rowstate set .setmodified() modified datatable.

for example:

...................................................

if row1 in orginal not equal row1 in modified row1.setmodified()

if row2 in orginal not equal row2 in modified then row2.setmodified()....etc

............................................................

it should not this:

............................................................

if row1 in orginal not equal row2 in modified row1.setmodified()

if row2 in orginal not equal row3 in modified row1.setmodified()...etc

............................................................

get idea? :)

any code suggestion without using primary keys?

using foreach loop within foreach n x n comparison, don't need do.

comparing first row first row of other table, second second , on using zip extension method useful case.

datatable original; datatable modified;  // stuff  modified = modified.asenumerable().zip<datarow, datarow, datarow>(original.asenumerable(), (datarow modif, datarow orig) => {     if (!orig.itemarray.sequenceequal<object>(modif.itemarray))     {         modif.setmodified();     }     return modif; }).copytodatatable<datarow>(); 

Comments