Hi all
I'm new using LinQ.
Im having Specified Cast not Valid in this Function.
Hope someone let me know what I'm doing wrong.
this is the Function
Private Function GroupedBy() As DataTable
Dim Sales As New ds_Sales_OELI
Dim dt As DataTable = Sales.Not_SCheduled
GroupedBy = New DataTable
Dim dr As DataRow
With GroupedBy
.Columns.Add("ProDate", GetType(String))
.Columns.Add("ttlCabs", GetType(Integer))
End With
Dim ReadyProduction As IEnumerable(Of DataRow) = dt.AsEnumerable
Try
Dim QUERY =
From InPro In dt.AsEnumerable
Group InPro By production = InPro.Field(Of String)("inProduction") Into G = Group
Select New With
{
.category = production,
.cab1 = G.Sum(Function(inpro) inpro.Field(Of Integer)("CabCat1")),
.cab2 = G.Sum(Function(inpro) inpro.Field(Of Integer)("CabCat2"))
}
For Each InPro In QUERY
dr = GroupedBy.NewRow
With GroupedBy
dr.Item("ProDate") = InPro.category
dr.Item("ttlCabs") = InPro.cab1 + InPro.cab2
End With
Next
Catch ex As Exception
MsgBox(Me.Text & " GroupedBy " & ex.Message)
End Try
End Function