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

    How Do You Add a Null in a DateTime Field?

    Good morning everybody.

    I'm trying to add a null into a SQL Server DateTime column called ShippedDate. With the below code I get an error message that says "Nullable object must have a value". This is driving me crazy. How do I do this?

    Code:
        private void InsertHeader(Guid inG)
        {
            DateTime now = DateTime.Now;
    
            string po = txtPoNumber.Text;
            string cn = ddlCustomer.Text;
            DateTime? shippeddate = null;
            OrderHeaderBll.Insert(inG, now, calStartDate.SelectedDate, po, cn, shippeddate.Value);
        }

  2. #2
    Join Date
    Dec 2009
    Posts
    596

    Re: How Do You Add a Null in a DateTime Field?

    Never mind guys. I found the solution. Thanks for looking.

    cmd.Parameters.AddWithValue("@ShippedDate", DBNull.Value);

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