0
    Private m_ExpirationDate As Nullable(Of DateTime)
Public Property ExpirationDate() As Nullable(Of DateTime)
    Get
        Return m_ExpirationDate
    End Get
    Set(ByVal value As Nullable(Of DateTime))
        m_ExpirationDate = value
    End Set
End Property


Dim rec As New DBML.Staff With _
        {.StaffDesc = m_StaffDesc, _
         .LastName = m_LastName, _
         .FirstName = m_FirstName, _
         .MiddleInit = m_MiddleInit, _
         .Gender = m_Gender, _
         .Certification = m_Certification, _
         .ExpirationDate = m_ExpirationDate, _ ********
         .Active = m_Active, _
         .CEPDNo = m_CEPDNo, _
         .FaNo = m_FaNo, _
         .PIC = m_PIC, _
         .PICValid = m_PICValid, _
         .PICCheckDate = Today(), _
         .PICError = m_PICError}

    _db.Staffs.InsertOnSubmit(rec)

    Try
        _db.SubmitChanges()
        RetVal = rec.StaffID.ToString
    Catch exp As Exception
        RetVal = "Insert Failed:" & exp.Message

    End Try

当我运行 insertonsubmit 时,它会失败,因为 m_ExpirationDate 的值为 null,尽管它显示 12:00:00:00AM。那么我该如何测试这个值,如果它为空,请不要将它包含在“InsertOnSubmit”语句中。我不想传递像 1/1/1900 这样的虚假值。

任何帮助表示赞赏。

4

1 回答 1

0
    Private m_ExpirationDate As Nullable(Of DateTime)
Public Property ExpirationDate() As Nullable(Of DateTime)
    Get
        Return m_ExpirationDate
    End Get
    Set(ByVal value As Nullable(Of DateTime))
        If Not IsDate(value) Or value = #12:00:00 AM# Then
            m_ExpirationDate = Nothing
        Else
            m_ExpirationDate = value
        End If

    End Set
End Property

我需要做的是将我的属性值设置为“无”,如果它是一个空白值或不是一个日期。

于 2013-03-29T13:00:27.703 回答