Handling a DateTime DBNull

前端 未结 6 1859
广开言路
广开言路 2021-01-18 00:32

I have seen many, many versions of this on SO, but none of them seem to quite work for my needs.

My data comes from a vendor database that allows null for DateTime

6条回答
  •  梦毁少年i
    2021-01-18 00:56

    Use IsDBNull()

    System.Convert.IsDBNull(value);
    

    or if you have a SqlDataReader

    reader.IsDBNull(ordinal);
    

    And make your DateTime properties to be nullable (DateTime?) and set null in case of DBNull. Field() will automatically do this.

提交回复
热议问题