VB.NET从DataTable中选择字段不为空

时间:2016-02-01 21:49:25

标签: vb.net linq select datatable where

我有一个数据表,我试图选择过去一个月内有日期字段的所有行:

Dim thisMonthQuery =
    From email In DataTablePickers.AsEnumerable() _
    Where email.Field(Of DateTime)("GenDateScheduled") >= New DateTime(curYear, curMonth, 1) _
    Select email

If thisMonthQuery.Any() Then
    Dim thisMonthData = thisMonthQuery.CopyToDataTable()
End If

问题是我的一些行有一个空的GenDateScheduled字段,它会抛出错误"无法强制转换DBNull.Value来键入' System.DateTime'"。我需要在Select语句中检查字段是否为空,但我不知道该怎么做。我认为它会像

Dim thisMonthQuery =
    From email In DataTablePickers.AsEnumerable() _
    Where email.Field("GenDateSchedule") Is Not Nothing And email.Field(Of DateTime)("GenDateScheduled") >= New DateTime(curYear, curMonth, 1) _
    Select email

但这不对。

0 个答案:

没有答案