C# cross join datatable

1.6k views Asked by At

How to obtain cross join for two datatables in C#

dataTable1 - 
          col1 
           a    
           b    

dataTable2 - 
          col2
           c
           d

I want output as follows:

dataResult - col1 col2 
               a    c 
               a    d   
               b    c   
               b    d 

How this can be achieved?

2

There are 2 answers

1
Daniel On BEST ANSWER

Something like this should do it:

var results = from dt1 in dataTable1.AsEnumerable()
              from dt2 in dataTable2.AsEnumerable()
              select new { dt1, dt2 };
0
K.Suthagar On

you can just join two tables of this,

SELECT A.col1,B.col2 FROM dataTable1 A JOIN datatable2 B