How to set DateTime to null

前端 未结 6 1174
半阙折子戏
半阙折子戏 2021-01-31 13:25

Using C#. I have a string dateTimeEnd.

If the string is in right format, I wish to generate a DateTime and assign it to eventCustom.DateTimeEnd

6条回答
  •  悲&欢浪女
    2021-01-31 14:21

    Now, I can't use DateTime?, I am using DBNull.Value for all data types. It works great.

    eventCustom.DateTimeEnd = string.IsNullOrWhiteSpace(dateTimeEnd)
      ? DBNull.Value
      : DateTime.Parse(dateTimeEnd);
    

提交回复
热议问题