本文介绍了DateTime问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,


我总是在努力解决以下问题:


我有一个对象obj,其属性为paydate(type = DateTime)

现在,在实例化对象并执行几项操作之后,我还要检查我的paydate是否仍然是空的。

我该怎么做?


我尝试过几样的事情(都有错误):

if(obj.paydate == null)

if(obj.paydate.gettype( )== System.DBnull)

if(obj.paydate == 01/01/0001)

等.....


另一个问题:

当我想要实例化对象并用sql-query(sql-database)中的数据填充它时。从sql for paydate = null接收的值。

如何在datareader中测试从sql接收的数据是否为空,因此我没有在obj.paydate中放置任何内容。

tkx,

Nic

解决方案



hey,

I always struggle with the following:

I have an object obj with a property paydate (type = DateTime)
Now, after instantiating the object and do several things, I want too check if my paydate is still empty.
How can I do this?

I tried several things like (all with errors):
if (obj.paydate == null)
if (obj.paydate.gettype() == System.DBnull)
if (obj.paydate == 01/01/0001)
etc.....

Another question :
When I want to instantiate the object and fill it with data from an sql-query (sql-database). The value received from sql for paydate = null.
How can I test in the datareader that the received data from sql is null and so I put nothing in obj.paydate.
tkx,
Nic

解决方案



Use the IsDbNull() in the DataReader. You''ll still have to work out
what to put into paydate in that case though.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too



这篇关于DateTime问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 15:06