How to get nullable DateTime out of the database

后端 未结 7 1389
滥情空心
滥情空心 2020-12-01 18:04

My SQL Server database contains nullable DateTime values. How can I convert them to a nullable DateTime object in my application in C#?

This is what I would think it

相关标签:
7条回答
  • 2020-12-01 18:59

    You need to check if the value "is DBNull" rather than just null. I posted a small helper class on my blog: http://improve.dk/archive/2007/10/08/handling-dbnulls.aspx

    Once you implement the class, you use it like this:

    DateTime? dt = DBConvert.To<datetime?>(sqldatareader[0]);
    
    0 讨论(0)
提交回复
热议问题