[Linq] Join query to datatable with anonymous type in VB.Net RRS feed

  • Question

  • Hi,
    i've a problem i can't solved:

    i have the following query :


    Dim query
    query = From lh In ds.Tables(0).AsEnumerable _
    Join emp In EmployeeListDataSet.Tables(0).AsEnumerable _
    On lh.Field(Of String)("Ho No") Equals emp.Field(Of String)("HONO") _
    Select New With {.srno = lh.Field(Of Integer)("SRNO"), _
    .hono = lh.Field(Of String)("HO No"), _
    .date = lh.Field(Of DateTime)("Date"), _
    .hours = lh.Field(Of Decimal)("Hours"), _
    .rate = lh.Field(Of Decimal)("Rate"), _
    .total = lh.Field(Of Decimal)("Total"), _
    .Employee = emp.Field(Of String)("NAME") _

    i want to put the result into a datatable but i always got the following error :


    Unable to cast object of type '<JoinIterator>d__61`4
    to type 'System.Data.DataTable'
    I've already tried to implement the custom CopyToDataTable function but it's doesn't work.

    Can you help me ?


    Wednesday, March 3, 2010 5:09 AM


  • Hi Julien,

    I dont think you can do that. Datatable does not implement IEnumerable and hence I dont think you can convert LINQ results to datatables.

    Thursday, March 4, 2010 5:35 PM

All replies