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

When I run the insertonsubmit it will fail bacause the value of the m_ExpirationDate is null, though it shows 12:00:00:00AM. So how can I test this value and if it is null don't include it in the "InsertOnSubmit" statement. I don't want to pass a phoney value like 1/1/1900.

Any help is appreciated.

Tom S
  • 227
  • 1
  • 6
  • 19
  • 2
    Well what does the database schema look like? – Jon Skeet Mar 28 '13 at 20:56
  • if you are not using a Nullable DateTime, you will have to put something in there. – DJ Burb Mar 28 '13 at 22:11
  • The table field for the ExpirationDate is a datetime field that allows null values. So again the question is how do I pass a null value in the context of the above LINQ query? I could create (2) queries, leaving the field out of one, in the event it is null, but that sure seems like a hack situation. – Tom S Mar 29 '13 at 11:42

1 Answers1

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

What I needed to do was set my property value to "nothing" if it was a blank value or not a date.

Tom S
  • 227
  • 1
  • 6
  • 19