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);
}
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);