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.DataRow,System.Data.DataRow,System.Dec imal,VB$AnonymousType_0`10[System.Decimal,System.DateTime,System.DateTime,Sys tem.DateTime,System.DateTime,System.Decimal,System .Decimal,System.String,System.String,System.String]]' to type 'System.Data.DataSet'."
I am not sure why it is not working. My code is as below. Please guide me. thank you
Expand|Select|Wrap|Line Numbers
- 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()