如果日期值为null,如何将日期值分配给日期变量 [英] how to assign a datevalue to the date varaible if it is null

查看:105
本文介绍了如果日期值为null,如何将日期值分配给日期变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好

请您告诉我如何存储价值 如果   _dateto值为空,则为'31 -12-2060'。

Please can you let me know how can store the value  as '31-12-2060' if the  _dateto value is null

DateTime _dateto = Convert.ToDateTime(row1 [" ENDDATE"] .ToString());

DateTime _dateto = Convert.ToDateTime(row1["ENDDATE"].ToString());

polachan

推荐答案

DateTime _dateto = Convert.ToDateTime(Convert.IsDBNull(row1["ENDDATE"]) ? row1["ENDDATE"] : "2060-12-31");



另一方面,如果获取/分配数据的方法只是将null赋给数据字段:


On the other hand, if your method of fetch/assign data will just assign null to the data field:

DateTime _dateto = Convert.ToDateTime(row1["ENDDATE"] ?? "2060-12-31");


这篇关于如果日期值为null,如何将日期值分配给日期变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆