Insert DateTime as Null

Discussion in '.NET' started by tenaciousD, Jul 3, 2009.

  1. tenaciousD

    tenaciousD

    Joined:
    Feb 2, 2009
    Messages:
    2
    The code will insert DateTime as 01 Jan 1910, how can it be inserted as blank ?

    Code:
    DateTime Date2;
    
    [B]WebForm[/B]
    if (txtDate.Text.ToString() == "")
    {
    Date2 = Convert.ToDateTime("1910/Jan/01");
    }
    else
    {
    Date2 = Convert.ToDateTime(txtDate.Text.ToString());
    }
    
    [B]DB[/B]
    if (demItem.InvoiceDate.ToString("yyyy/MM/dd") == "1910/Jan/01")
    {
    cm.Parameters["@invoiceDate"].Value = DBNull.Value;
    }
    else
    {
    cm.Parameters["@invoiceDate"].Value = Convert.ToDateTime(Date2);
    }
    
     
    tenaciousD, Jul 3, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christos TZOTZIOY Georgiou
    Replies:
    3
    Views:
    765
    Christos TZOTZIOY Georgiou
    Sep 13, 2003
  2. Tim Peters
    Replies:
    0
    Views:
    602
    Tim Peters
    Sep 9, 2003
  3. mp
    Replies:
    1
    Views:
    442
    John Machin
    Jul 28, 2006
  4. Martin
    Replies:
    0
    Views:
    377
    Martin
    Dec 27, 2008
  5. skip@pobox.com
    Replies:
    2
    Views:
    803
    M.-A. Lemburg
    Jan 6, 2009
Loading...

Share This Page