Merge two DataTable in .Net
Recently I had a need to merge two DataTables with same structure, DataSet has built-in function called Merge but not in DataTable.
So I wrote my own, this is my function to merge two DataTables…
public static DataTable mergeDTs(DataTable dt1, DataTable dt2)
{
DataTable dtResult = dt1.Clone();
foreach (DataRow dr in dt1.Rows)
{
dtResult.Rows.Add(dr.ItemArray);
}
foreach (DataRow dr in dt2.Rows)
{
dtResult.Rows.Add(dr.ItemArray);
}
return dtResult;
}
Hope this helps.
this was great, thanks. it actually seemed to work better than .merge() that is included in vb.net
Stu
February 17, 2009 at 9:55 pm
greeat……
Anton
May 15, 2009 at 2:49 pm
Greatest Logic ever invented ..u R the next Einstein
Dax
September 6, 2010 at 1:11 pm
Thank you for your code helped me a lot
Izaias
September 9, 2011 at 3:07 am