dtPivot(is a var datatable) = (From d In dtPv.AsEnumerable
Group d By k=d(“Soc.”).toString.Trim, k2= d(“Codici iva”).ToString.Trim, k3=d(“Registro”).ToString.Trim,k4=d(" M").ToString.Trim Into grp=Group
Let cs1 = grp.Sum(Function (x) Convert.ToDouble(x(" Imp. base imponibile").toString.Trim))
Let cs2 = grp.Sum(Function (x) Convert.ToDouble(x(" IVA vendite").toString.Trim))
Let cs3 = grp.Sum(Function (x) Convert.ToDouble(x(“IVA vend.da vers”).toString.Trim))
Let ra = New Object(){k,k3,grp.First()(“CI”),k2,k4,cs1,cs2,cs3}
Select dtPv.Rows.Add(ra)).CopyToDataTable
where dtPv is a datatable
I have been using this workflow for over a month and have never received any errors. Now it shows me the following error
Could you try Updating your Query to the Below and Check :
(From d In dtPv.AsEnumerable
Group d By k=d("Soc.").toString.Trim, k2= d("Codici iva").ToString.Trim, k3=d("Registro").ToString.Trim,k4=d(" M").ToString.Trim Into grp=Group
Let cs1 = grp.Sum(Function (x) Convert.ToDouble(If(x(" Imp. base imponibile").toString.Trim.IsNumeric,x(" Imp. base imponibile").toString.Trim,"0")))
Let cs2 = grp.Sum(Function (x) Convert.ToDouble(If(x(" IVA vendite").toString.Trim.IsNumeric,x(" Imp. base imponibile").toString.Trim,"0")))
Let cs3 = grp.Sum(Function (x) Convert.ToDouble(If(x("IVA vend.da vers").toString.Trim.IsNumeric,x(" Imp. base imponibile").toString.Trim,"0")))
Let ra = New Object(){k,k3,grp.First()("CI"),k2,k4,cs1,cs2,cs3}
Select dtPv.Rows.Add(ra)).CopyToDataTable
There is an Additional Check on the column values to decide if it is numeric value or not, if Numeric, then we should be able to use the column value for converting to a Double.