DataTable Merge

patrick

Well-known member
Joined
Dec 5, 2021
Messages
251
Programming Experience
1-3
Hello

I am trying to combine different DataTables.
DataTable--1 ==> Matrix : 3row * 4column ==> DataTable is created.
삭제11.png


DataTable--2 ===> Matrix : 3row * 4column ==> DataTable is created.
삭제22.png



I don't know how to join the different DataTable--1 and DataTable--2 that have been created.
===> Matrix : 3row * 8column

삭제33.png


===> How do you join DataTables in C#?

Awaiting your reply.
Thank you
 
The OP is not trying to do a JOIN. The OP is trying to merge the columns of two different tables together.

I think the first step is to transpose both tables to be:
C#:
Name Age
Alex 21
James 24
Kevin 23

:

Name Age
Joel 20
Gregory 25
Henry 22

Then just add the rows of one table into the other. And after that, then transpose the results back.
 
The OP is not trying to do a JOIN

Looking at the pictures, seems to me that a join is exactly what they're attempting?

If those are the tables with those rows in that order then it could even be joined on row number (for loop index) .. If not the same order then it looks like a join on column 1 on each side (name=name, age=age, etc)

Those tables pictured are, of course, totally wonky - a table does not have a column that has values "Joel 20 Columbia" with the 20 right aligned as if it were a number..
..unless we're being really nasty and making the columns' datatypes as object
 
Last edited:
Perhaps OP should show us a screenshot of the DataTable Visualizer pane in the debugger, revealing their actual datatable.. Rather than some stylized excel mock-up
 
The OP is not trying to do a JOIN. The OP is trying to merge the columns of two different tables together.

I think the first step is to transpose both tables to be:
C#:
Name Age
Alex 21
James 24
Kevin 23

:

Name Age
Joel 20
Gregory 25
Henry 22

Then just add the rows of one table into the other. And after that, then transpose the results back.

OP ==> It is Library ??
Where is download the OP.
 
Last edited:
OP == Original Poster: @patrick

OP is not a library.
 
What is going on with that data? Where is it coming from? You are using the term "DataTable". Do you mean a System.Data.DataTable object? If so, how did you create it and how did you populate it? It looks to me like you should have a table with three columns: Name, Age and School. You should then have six rows in total. It seems that your data is pivoted for no good reason.
 
Back
Top Bottom