Click here to Skip to main content
15,885,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

I am trying to merge 2 datatables into one. I do not want the merge the second datatable to the below of the first one. I need them to be side by side. I have tried;
C#
dtAll = dt1.Copy();
dtAll = dt2.Merge(); // This adds the dt2 below

After googling, I have found that site[^].Is there a better way to solve this?
Thanks in advance.
Posted

We can't really answer that.
The problem is that we don't know how the two tables are interrelated: or even if they are!

If you have two tables which have a common element - a UserID say - then you need to merge them into a new table so that a row in TableA with UserID 1234 is combined with the row from TableB where it's UserID is also 1234 and so forth. If there is no such element, then the two sets of information are not interdependent and probably shouldn't be combined anyway.

And if you do have such a relationship, then you are probably better filling a single table from your datasource in the first place!

I think you need to re-think your problem in terms of "why am I trying to do this?" before you continue any further.
 
Share this answer
 
v2
Comments
wonder-FOOL 26-Sep-13 3:03am    
Both tables are generated the same way but the rows which contains the data differs. So the headers match. So this elimates your concerns on the second paragraph. The link actually solves my problem but I am just curious if there is a better solution. Tho thank you very much for your answer, time and efforts.
dtAll = dt1.Copy();

dtAll.Merge(dt2);
 
Share this answer
 
Comments
Orcun Iyigun 26-Sep-13 2:57am    
Seriosly? What is this? Have you read the question? It is even highlighted!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900