How to Merge two DataTable and Get a Distinct Records from the Table using C#

Hi
     suppose we have two datatables dt1and dt2 first i marge both the datatables and then get the distinct records

  dt1 have some data &dt2 have some data now marge dt2 in dt1

                  dt1.Merge(dt2 ); //Here we marge the datatables

                  dt1.GetChanges();// Get Changes

Now we find the Distinct records of DataTable dt1

  dt1= dt1.DefaultView.ToTable(true, cols); //DedaultView return the Distinct record but before that we have to pass datatable column Array (cols) to this method. here cols us a array if column if Datatable.

hope this will help You

Regard,
Rajesh

0 comments: