none
[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
    Try
    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
    [System.Data.DataRow,System.Data.DataRow,System.String,VB$AnonymousType_0`7[
    System.Int32,System.String,System.DateTime,System.Decimal,System.Decimal,System.Decimal,System.String]]'
    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 ?

    Julien

    Wednesday, March 3, 2010 5:09 AM

Answers

All replies