0

Is there a way in linq to join two DataTables and store the result in another DataTable? And I mean a DataTable not the hierarchical form that group join creates.

Here is the code for group join that i have got so far. Which works, but I don't understand what to do with the result.

var temp = from t1 in table1
           join t2 in table2
           on t1.Field<string>("a")
           equals t2.Field<string>("b") into t
           select t;

And also, how does one use the hierarchical form created by group join anyway?

Aditi
  • 1,188
  • 2
  • 16
  • 44
  • A similar question i've answered yesterday: [Can't copy LINQ result into DataTable](http://stackoverflow.com/questions/14578235/cant-copy-linq-result-into-datatable) – Tim Schmelter Jan 30 '13 at 13:21

1 Answers1

0

That LINQ query should give you a collection of DataRow objects, correct? You could try using this approach on SO to convert the rows into a new table.

Community
  • 1
  • 1
Brian Mains
  • 50,520
  • 35
  • 148
  • 257
  • The type is `System.Collections.Generic.IEnumerable> {System.Linq.Enumerable.GroupJoinIterator>}` – Aditi Jan 31 '13 at 04:45
  • I'm not sure why it's double enumerable from that query, and that is the problem. You could try to get around that by doing at the end t.SelectMany(i => i) and see if that resolves the problem. SelectMany is supposed to flatten a resultset. Not sure if that will work. – Brian Mains Jan 31 '13 at 13:40