Tuesday, 5 March 2013

VB.NET - How to fix error vb.net Cannot cast DBNull.Value to type 'System.DateTime'. Please use a nullable type.

VB.NET LINQ to DataSet
Cannot cast DBNull.Value to type 'System.DateTime'. Please use a nullable type.

Replace

Dim SalesOrder = ds.Tables("SO").AsEnumerable()
  Dim SO = From h In SalesOrder
             Group h By TransactionDate= h.Field(Of DateTime)("transDate") _
             Into Group _
             Select  TransactionDate

With

Dim SalesOrder = ds.Tables("SO").AsEnumerable()
  Dim SO = From h In SalesOrder
             Group h By TransactionDate= h.Field(Of DateTime?)("transDate") _
             Into Group _
             Select  TransactionDate

No comments:

Post a Comment