Reputation: 880
i have the following code which will get the max and min values from a list of type double
Dim sprices As List(Of Double) = grp.ProductGroups.AsEnumerable().[Select](Function(sm) sm.Field(Of Double)("sprice")).Distinct().ToList()
Dim min As Integer = sprices.Min()
Dim max As Integer = sprices.Max()
how ever in the first line i get the exception "Cannot cast DBNull.Value to type 'System.Double'. Please use a nullable type." how can i avoid this or not add the DBNulls to the list?
Upvotes: 0
Views: 685
Reputation: 2531
One way is to use a nullable Double
, which can be expressed as Double?
:
Dim sprices As List(Of Double?) = grp.ProductGroups.AsEnumerable().[Select](Function(sm) sm.Field(Of Double?)("sprice")).Distinct().ToList()
Upvotes: 2