CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2009
    Posts
    596

    [RESOLVED] how to insert null date

    Hey everyone. I have some date fields that I want to not have any dates during a record creation. I figured the way to go would be to insert NULL. The way I'm going about it now gives me a Type mismatch error. How do I go about doing this? VB 2008 Standard/Access 2007

    Code:
      command.CommandText = "INSERT INTO IssueTbl(HardwareID,SoftwareID,Description,OpenedDate,AssignedDate,ClosedDate) " & _
               "VALUES('" & selHardware & "', " & _
               "'" & selSoftware & "', " & _
               "'" & Me.txtDescription.Text & "', " & _
               "'" & Now & "', " & _
               "'" & DBNull.Value & "', " & _
               "'" & DBNull.Value & "')"
    Last edited by viperbyte; November 24th, 2010 at 01:46 PM. Reason: Forgot to mention IDE and database

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: how to insert null date

    The DB has to have NULLABLE types. That's a bad way to initialize a date, though. Create one from 100 years ago, or 1000.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Dec 2009
    Posts
    596

    Re: how to insert null date

    I used the 1000 years approach. That worked but I hope to one day know how others feel about how to setup a datetime field that won't have real information in it till the future. Thanks for the suggestion.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured