0

I joined two datatables & trying to get the results in the array.

dt
ID   A    B    C
1    ab   t    j
2    cd   h    k
3    ds   f    g

ndt
CID     E    F   G
1       g    y   gg
2       ff   hg  vcb
3       df   vb   b

Code

var query = from r0w1 in dt.AsEnumerable()
            join r0w2 in ndt.AsEnumerable()
                 on r0w1.Field<string>("ID") equals r0w2.Field<string>("CID")
                 select r0w2.ItemArray.Concat(r0w1.ItemArray).ToArray();

What I want here is no to select the column CID from above result since both the columns ID & CID are same. How can I avoid it ?

1
  • can u show sample data inputs and expected output? Commented Dec 14, 2015 at 5:51

1 Answer 1

1

Assuming that CID always goes first in your row, you can utilize LINQ Skip to skip the first item:

var query = from r0w1 in dt.AsEnumerable()
            join r0w2 in ndt.AsEnumerable()
            on r0w1.Field<string>("ID") equals r0w2.Field<string>("CID")
            select r0w2.ItemArray.Skip(1).Concat(r0w1.ItemArray).ToArray();
Sign up to request clarification or add additional context in comments.

2 Comments

Sorry, that was writing mistake, but that was not the actual problem.
This answer should work provided that "CID" is first column as shown in output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.