I've a datatable named which contains data with a column of ID, firstname, lastname. Another datatable contains columns of code, userID1
, userID2
, userID3
, work.
Now i want a new datatable which should contain the column of both the datatable with proper data.
New datatable should contain data as: ID
, userfullname1
, userfullname2
, userfullname3
, work.
Here we get the value of userfullname1
by firstname, lastname of datatable1 & userID1
of datatable2
. Similarly we get the value of userfullname2
by firstname, lastname of datatable1
& userID2
of datatable2
& so on.
The value of ID in Datatable1
is same as userID1
, userID2
, userID3
in Datatable2
.
Finally, i want to obtain a new datatable with code, userfullname1, userfullname2, userfullname3, work. But users IDs are in datatable1. So, i want to bind the names of Datatable1 to the all 3 userids of Datatable2 via their IDs whichare present in both the tables.
Datatable1 :
iD name
1 b
2 d
3 f
4 s
....
Datatable2 :
Code userid1 userid2 userid3 work
1f 1 3 6 gg
2g 1 4 7 gg
3b 3 4 7 gg
4v 4 3 8 gg
New Datatable :
Code username1 username2 username3 work
1f a b c gg
2g d f r gg
3b c h g gg
4v d s h gg
How can i join & get the new datatable ?
If you just want your resulting table to have name and id, you should do it like this:
It sounds like you have a table with User Ids and you want to join your profile table to get those names. You can do this with sub-queries like:
You can do it with joins like:
You can use LINQ to achieve what you want: