2

I can't save values into two nullable columns.

This is the entity I'm saving:

  nquote_orderheaders header = new nquote_orderheaders()
            {
                CreatedDate = DateTime.Now,
                SendDate = DateTime.Now,
                SentByUser = accountInfo.Username,
                CreatedByUser = accountInfo.Username,
                QuoteOrderNumber = tempQuoteNumber,
                IMCustomerNumber = resellerInfo.CustomerNo,
                CustomerEmail = accountInfo.Username,
                CustomerName = resellerInfo.CustomerName,
                UserComment = "",
                StatusId = 1,
                CustomerId = data.CustomerId,
                ExpirationDate = DateTime.Now.AddDays(14)
            };

The SendDate and ExpirationDate fields are nullable Datetimes. They end up null in the database.

I'm using MySql with MySqlConnector 6.5.4. Any suggestions greatly appreciated.

3
  • IS CreatedDate end with out nullable. Commented Oct 30, 2013 at 11:16
  • 1
    Can you paste in your Entity class? Commented Oct 30, 2013 at 14:22
  • I don't know about MySqlConnector, maybe it's very picky about matching types. You may try to set nullable DateTime values: SendDate = new Nullable<DateTime>(DateTime.Now). Commented Oct 30, 2013 at 21:34

1 Answer 1

2

You have to cast DateTime.Now to the Nullable just like the following code:

CreatedDate = DateTime.Now as DateTime?,

or using longer form:

CreatedDate = DateTime.Now as Nullable<DateTime>,
Sign up to request clarification or add additional context in comments.

1 Comment

Still saves a null date.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.