.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Collections >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

compare two datatables and get the result

Posted By:Venkat       Posted Date: August 04, 2009    Points: 10    Category: Collections    URL: http://www.dotnetspark.com  
 

compare two datatables in and get the result in another table with the changes rows.

This Method is used to compare 2 dataTable and return the difference in 3rd datatable. In this example we are going to use GetChanges method of dataTable which will give us the difference rows.

Below function takes two parameter of type datatable and return you datatable.


In C#

public static DataTable CompareTwoDataTable(DataTable dt1, DataTable dt2)

        dt1.Merge(dt2);

DataTable d3 = dt2.GetChanges();


return
d3;

}

Vb.NET

Public Shared Function CompareTwoDataTable(ByVal dt1 As DataTable, ByVal dt2 As DataTable) As DataTable   

       dt1.Merge(dt2)

Dim d3 As DataTable = dt2.GetChanges()


Return
d3

End Function


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend