19 June 2014

Comparing two datatables and returning a datatable by matching rows in c#.net using linq



  public DataTable get_Comparing(DataTable dt1, DataTable dt2)
   {
      DataTable dtMerged = (from a in dt1.AsEnumerable()
                                  join b in dt2.AsEnumerable()
                            on a["Student_Id"].ToString() equals b["Student_Id"].ToString()
                                  into g
                                  where g.Count() > 0
                                  select a).CopyToDataTable();

            return dtMerged;
   }

No comments:

Post a Comment