将DateTime值设置为null

编程入门 行业动态 更新时间:2024-10-10 19:24:03
本文介绍了将DateTime值设置为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好, 我有DateTime属性。 如何将此值设置为null? 我尝试DBNull.Value但它不起作用。 非常感谢, Ruslan

推荐答案

news.microsoft< ru ********* @ hotmail>写道: news.microsoft <ru*********@hotmail> wrote: 我有DateTime属性。 如何将此值设置为null? I have DateTime property. How can I set this value to null?

你可以' - 就像你不能将int属性设置为null,或者将任何 其他值类型属性设置为null。 null是一个引用,并且 与值类型不兼容。 - Jon Skeet - < sk ** *@pobox> www.pobox/~双向飞碟 如果回复小组,请不要给我发邮件

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> www.pobox/~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>在消息中写道 新闻: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> wrote in message news:MP************************@msnews.microsoft.c om... news.microsoft< ru ********* @ hotmail>写道: news.microsoft <ru*********@hotmail> wrote: 我有DateTime属性。 如何将此值设置为null? I have DateTime property. How can I set this value to null?

你不能 - 就像你不能将int属性设置为null,或任何其他值类型属性为null。 null是一个引用,并且与值类型不兼容。 - Jon Skeet - < sk *** @ pobox> www.pobox/~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> www.pobox/~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> www.pobox/~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> www.pobox/~skeet If replying to the group, please do not mail me too

更多推荐

将DateTime值设置为null

本文发布于:2023-10-28 10:50:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1536424.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:设置为   DateTime   null

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!