将DateTime值设置为null [英] Set DateTime value to null
问题描述
您好,
我有DateTime属性。
如何将此值设置为null?
>
我尝试DBNull.Value但它不起作用。
非常感谢,
Ruslan >
推荐答案
news.microsoft.com< ru ********* @ hotmail.com>写道:
news.microsoft.com <ru*********@hotmail.com> wrote:
我有DateTime属性。
如何将此值设置为null?
I have DateTime property.
How can I set this value to null?
你可以' - 就像你不能将int属性设置为null,或者将任何
其他值类型属性设置为null。 null是一个引用,并且
与值类型不兼容。
-
Jon Skeet - < sk ** *@pobox.com>
http://www.pobox.com/~双向飞碟
如果回复小组,请不要给我发邮件
You can''t - just like you can''t set an int property to null, or any
other value type property to null. null is a reference, and is
incompatible with value types.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
哎呀,我觉得DateTime是一个引用类型。因此,如果我需要为存储过程的参数分配一个
null值,我必须写:
command.Parameters.Add(" @ declaration_date" ;,SqlDbType.DateTime).Value =
DBNull.Value;
还是有另一种方式?
谢谢
Ruslan
" Jon Skeet [C#MVP]" < SK *** @ pobox.com>在消息中写道
新闻:MP ************************ @ msnews.microsoft.c om ...
Oops, I thought what DateTime is a reference type. So if I need to assign a
null value to a parameter for stored procedure I have to write:
command.Parameters.Add("@declaration_date", SqlDbType.DateTime).Value =
DBNull.Value;
or there is another way?
Thanks
Ruslan
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
news.microsoft.com< ru ********* @ hotmail.com>写道:
news.microsoft.com <ru*********@hotmail.com> wrote:
我有DateTime属性。
如何将此值设置为null?
I have DateTime property.
How can I set this value to null?
你不能 - 就像你不能将int属性设置为null,或任何
其他值类型属性为null。 null是一个引用,并且与值类型不兼容。
-
Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet
如果回复小组,请不要给我发邮件
You can''t - just like you can''t set an int property to null, or any
other value type property to null. null is a reference, and is
incompatible with value types.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
你好Jon,
当它是一个不动产你是正确的,但是日期值是
特别的东西需要时间让我在C#中确保给出正确的答案
答案。
所以我没有回答这个消息,当你在VBNet中向我展示这个消息时
作为财产或价值
mydate = nothing(是ISO 1900/01/01)
dr(" mydate")= dbnull.value
因为这是从ADONET回答的新闻组我认为这意味着
这个问题是最后一个问题。从中我假设它(几乎)恰好与C#相同,但是在我犯错误之前。
Cor
Hi Jon,
When it is a real property you are right, however the date value is
something special what takes time for me in C# to be sure to give the right
answer.
So I did not answer this message, can you when I show you this in VBNet
as a property or value
mydate = nothing (is ISO 1900/01/01)
dr("mydate") = dbnull.value
Because this is answered from the ADONET newsgroup I assume that is meant
with this question the last. From which I assume it is (almost) exactly the
same in C#, however before I make a mistake.
Cor
我有DateTime属性。
如何将此值设置为null?
I have DateTime property.
How can I set this value to null?
你可以' ' - 就像你不能将int属性设置为null,或将任何其他值类型属性设置为null。 null是一个引用,并且与值类型不兼容。
-
Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet
如果回复小组,请不要给我发邮件
You can''t - just like you can''t set an int property to null, or any
other value type property to null. null is a reference, and is
incompatible with value types.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
这篇关于将DateTime值设置为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!