Data Tables can be easily compared. This comparison can be done using Merge () and GetChanges() methods of DataTable class object.
In this article, I am taking 3 DataTable class object- dataTable1, dataTable2 and dataTable3
Here dataTable3 will hold the comparison result of dataTable1 and dataTable2.
Here is simple code-
//Merging datatable2 to data table
dataTable1.Merge(dataTable2);
//Getting changes in dataTable3
DataTable dataTable3= dataTable2.GetChanges();
In above lines of code, first I am merging datatTable1 and dataTable2 and combined result will be stored in dataTable1. Finally to get changes I am using GetChanges() method of dataTable1 object.
DataTable dataTable3= dataTable2.GetChanges();
Here GetChanges() method will return one DataTable class object and returned result will be stored in dataTable3 object.
Thanks
No comments:
Post a Comment