Hello all.. i wanted to merge two datatables.. infact its only one which is original version and modified version.. merging both to find the differences and store them in another datatable. but for some reason merge is not working.. here is the code which i have written.

public static DataTable CompareDatatables(DataTable dtoriginal, DataTable dtModified)
        { 

            DataTable dt3 = new DataTable();
            DataTable dt4 = new DataTable();
            dt3 = dtModified.Copy();
            dt3.Merge(dtoriginal);
            dt4 = dt3.GetChanges();
            return dt4;
        }

dt4 is returning null and the values are not merging :( .. please help

Recommended Answers

All 5 Replies

If dtModified is the changed version of dtoriginal, dtModified.GetChanges() will give you the changes. A merged table doesn't have changes, it is supposed to be current. Check out the documentation on Merge

First i am passing dt modified in to dt3 datatable and then i am merging that dt3 which has the modified table with original table. so dt3 was now merged with both the tables. dt3.getchanges should give me the result i needed..thats where i am facing my problem..

I can see the modified data in dt3 now. .but dt3.getchanges() method is not working... when pass it in to new datatable it is returning null.. am i doing anything wrong? the modified table is subset of original table.. do do i need to merge otherway?? please help

First i am passing dt modified in to dt3 datatable and then i am merging that dt3 which has the modified table with original table. so dt3 was now merged with both the tables. dt3.getchanges should give me the result i needed..thats where i am facing my problem..

Once you do the merge there are no more changes pending, so you get nothing from GetChanges(). Again, dt3.GetChanges() done before the merge should return the changes, after the merge it is too late.

Why not you try to GetChanges() on the modified version of your datatable? Since you mentioned that it is a modified of the original, I guess you should be able to get the changes from 'dtModified'

dtModified.GetChanges();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.