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

Recommended Answers

All 3 Replies

Yes, but could you specify where?
Knowbody is going to help you with posting a blob of code and saying I have an error.

commented: Blob control + 1. +11

It's in this Line
.cab1 = G.Sum(Function(inpro) inpro.Field(Of Integer)("CabCat1")),

Found a Solution for the error.
all I had to do was change the following from integer to decimal.
.cab1 = G.Sum(Function(inpro) inpro.Field(Of Decimal)("CabCat1")),
.cab2 = G.Sum(Function(inpro) inpro.Field(Of Decimal)("CabCat2"))

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.