If you’ve had trouble trying to force an actual, truly blank/null value in a date field in an Access database, you probably aren’t alone.

The task of assigning a true null value, in this case, via the key word “Nothing”, requires the use of the Nullable(Of Date) type.

Google Nullable(of date) and .HasValue.

You’ll need both of those bits to make the whole thing work.

4 Responses to “vb.net: insert a truly null date in access db”

  1. dfdhfghf Says:

    how can i insert null value in date column in vb.net?

  2. hobbylobby Says:

    yes. look up nullable(of date) and .hasValue.

    it’s a little tricky to tie it all together, but you can make it work.

  3. Eric Says:

    Any other “Hints”?????

    I’m trying to condiinally “undo” a date if a parameter changes by:

    IIf([PMPPOU] And [PCPOU] And [PSSU] And [PAU] And [DPIRC] And [DMPU] And [DCPU] And [DBU] And [SSU] And [ERMPOC] And [PBN]=True,Date(), Null)

    If on eof the checkboxes changes to be not true than I want the Date field to go back to Null.

    I can’t get it to work.

  4. hobbylobby Says:

    vbnotebookfor.net has exactly what you need.

    he shows getting from a database, but not setting values to a database.

    here’s one way:
    If theDate.HasValue Then
    cmd.Parameters.Add(New OleDb.OleDbParameter(“@theDate”, theDate))
    Else
    cmd.Parameters.Add(New OleDb.OleDbParameter(“@theDate”, DBNull.Value))
    End If


Leave a Reply