How to get nullable DateTime out of the database

后端 未结 7 1516
滥情空心
滥情空心 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:47

    DateTime? dt = null;
    
    if (sqldatareader[0] != System.DbNull.Value)
    {
        dt = (DateTime)sqldatareader[0];
    }
    

提交回复
热议问题