I am grouping data in datatable and summing up one column using linq but while run time i am getting error stating that
Cannot cast DBNull.Value to type 'System.Int32. Please use a nullable type" Below is my code
Dim resultStyle = invData.Tables(0).AsEnumerable() _
.GroupBy(Function(v) New With {Key .InvestorStyleID = v.Field(Of Integer)("InstitutionalInvestorStyleID"), Key .StyleName = Not IsNothing(v.Field(Of String)("InstitutionalInvestorStyleName"))}) _
.Select(Function(v) New With {Key .InvestorStyleID = v.Key.InvestorStyleID, Key .StyleName = v.Key.StyleName, Key .Sum = v.Sum(Function(r) Double.Parse(r.Item("k001ICGeo").ToString()))})
Kindly suggest me how to avoid taking null value.I am getting error on second line
.GroupBy(Function(v) New With {Key .InvestorStyleID = v.Field(Of Integer)("InstitutionalInvestorStyleID"), Key .StyleName = Not IsNothing(v.Field(Of String)("InstitutionalInvestorStyleName"))}).
I don't want to take the null value.
v.Field(Of Integer?)("InstitutionalInvestorStyleID")