Sandip's Programming Zen

An attempt to share tech/coding experiences

Merge two DataTable in .Net

with 4 comments

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)
foreach (DataRow dr in dt2.Rows)

return dtResult;

Hope this helps.

Written by Sandip

July 9, 2008 at 11:25 am

Posted in .Net

4 Responses

Subscribe to comments with RSS.

  1. this was great, thanks. it actually seemed to work better than .merge() that is included in


    February 17, 2009 at 9:55 pm

  2. greeat……


    May 15, 2009 at 2:49 pm

  3. Greatest Logic ever invented ..u R the next Einstein


    September 6, 2010 at 1:11 pm

  4. Thank you for your code helped me a lot


    September 9, 2011 at 3:07 am

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: