Error when using LINQ to dataset

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • user1980
    New Member
    • Dec 2009
    • 112

    Error when using LINQ to dataset

    Hi,

    I am using LINQ to join two different datatables. I am trying to put the result in a dataset.

    This code was working fine till yesterday. But today when I run the code, it gives me the error,

    Unable to cast object of type '<JoinIterator> d__61`4[System.Data.Dat aRow,System.Dat a.DataRow,Syste m.Decimal,VB$An onymousType_0`1 0[System.Decimal, System.DateTime ,System.DateTim e,System.DateTi me,System.DateT ime,System.Deci mal,System.Deci mal,System.Stri ng,System.Strin g,System.String]]' to type 'System.Data.Da taSet'."

    I am not sure why it is not working. My code is as below. Please guide me. thank you

    Code:
      Dim dt2 As New DataTable
                dt2.Load(dr2)
                Dim dt3 As New DataTable
                dt3.Load(dr3)
              Dim ds As New DataSet
    
              
    
             Dim joinquery = From t1 In dt2.AsEnumerable() Join t2 In dt3.AsEnumerable() _
                        On t1.Field(Of Decimal)("CLASS_NUMBER") Equals t2.Field(Of Decimal)("CLASS_NUMBER") _
                        Select New With _
                          {Key .CLASS_NUMBER = t1.Field(Of Decimal)("CLASS_NUMBER"), _
                           Key .FACULTY_START_DT = t2.Field(Of DateTime)("FACULTY_START_DT"), _
                           Key .FACULTY_END_DT = t2.Field(Of DateTime)("FACULTY_END_DT"), _
                           }
                 
         ds = joinquery
                 
    
                NewDg.DataSource = ds
                NewDg.DataBind()
Working...