0

Hi I got some issues in transferring LINQ output in a datatable that I'll see on a DataGridView, Here is the Code;

I pass two datatables as parameters and then I receive an error in Join_Table.CopyToDataTable() saying anonymous types etc...

public DataTable Join(DataTable DT_Derivati, DataTable dt_Cambi)
{
   var Join_Table = from A in DT_Derivati.AsEnumerable()
                    join B in dt_Cambi.AsEnumerable() 
                    on A.Field<string>("CCY") equals B.Field<string>("Currency")
                    select new
                    {
                        CCY = (string)A["CCY"],
                        Importo = (int)A["IMPORTO"],
                        Cambio_ = (int)B["Quotazione"],
                        Nota_ = (int)B["Nota"]
                     };
   DataTable boundTable = ***Join_Table.CopyToDataTable***();

   return boundTable;
}

Any Tips?

ngunha02
  • 1,719
  • 1
  • 19
  • 24
FabriManga
  • 17
  • 1
  • 8
  • 1
    Possible duplicate of [Converting anonymous type to DataTable](http://stackoverflow.com/questions/7281286/converting-anonymous-type-to-datatable) – Rahul Singh Oct 21 '15 at 16:55
  • I'm kind of new to C#, could u explain a possible solution? – FabriManga Oct 21 '15 at 17:12
  • That's why I marked it as duplicate, you can check that answer. Your issue is anonymous type cannot be converted into a DataTable directly. As a side note if you are binding it to `DataGridView` then it's not mandatory that you need a DataTable only you can directly assign this anonymous type also. – Rahul Singh Oct 21 '15 at 17:17

0 Answers0