处理null和datetime [英] dealing with null and datetime

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

问题描述

有没有什么好方法可以处理null日期时间。例如,我似乎找不到任何会在日期时间

参数中将空值传递给另一个方法的东西。例如,Convert.dbnull不起作用。

在C#和SQL Server之间来回获取空值总是

有问题。


-

问候,

Gary Blakely

解决方案

" GaryDean" < Ga ****** @ newsgroups.nospamwrote in message

news:u7 ************** @ TK2MSFTNGP05.phx.gbl ...


有没有什么好方法可以处理null日期时间。例如,

我似乎找不到任何会在日期时间

参数中将null值传递给另一个方法的东西。例如,Convert.dbnull不起作用。

在C#和SQL Server之间来回获取空值总是有问题。



使用可以为空的DateTime变量,例如


DateTime? dtmNullable = null;


问题是DateTime是一个值类型。值类型不能为空。

我通常将2000年1月1日(或任何其他日期)设置为空日期并检查

,就好像你要检查一样null。


George。

" GaryDean" < Ga ****** @ newsgroups.nospamwrote in message

news:u7 ************** @ TK2MSFTNGP05.phx.gbl ...


有没有什么好方法可以处理null日期时间。例如,

我似乎找不到任何会在日期时间

参数中将null值传递给另一个方法的东西。例如,Convert.dbnull不起作用。

在C#和SQL Server之间来回获取空值总是

有问题。


-

问候,

Gary Blakely



对不起,我不明白。

什么是可空的DateTime变量?


什么是DateTime? dtmNullable = null;" ;?


您能否在代码中使用它?


谢谢

乔治。

" Mark Rae" < ma ** @ markNOSPAMrae.com写信息

新闻:ON ************** @ TK2MSFTNGP02.phx.gbl ...
< blockquote class =post_quotes>
" GaryDean" < Ga ****** @ newsgroups.nospamwrote in message

news:u7 ************** @ TK2MSFTNGP05.phx.gbl ...


>有没有什么好方法可以处理null日期时间。对于
实例,我似乎找不到任何会将
datetime参数中的null值传递给另一个方法的东西。 Convert.dbnull不适用于
实例。在C#和SQL Server之间来回获取空值总是有问题的。



使用可以为空的DateTime变量,例如


DateTime? dtmNullable = null;



Is there any good way in which to deal with null datetimes. For instance, I
can''t seem to find anything that will pass a null value in a datetime
parameter to another method. Convert.dbnull will not work for instance.
Getting nulls back and forth between C# and SQL Server is always
problematic.

--
Regards,
Gary Blakely

解决方案

"GaryDean" <Ga******@newsgroups.nospamwrote in message
news:u7**************@TK2MSFTNGP05.phx.gbl...

Is there any good way in which to deal with null datetimes. For instance,
I can''t seem to find anything that will pass a null value in a datetime
parameter to another method. Convert.dbnull will not work for instance.
Getting nulls back and forth between C# and SQL Server is always
problematic.

Use a nullable DateTime variable e.g.

DateTime? dtmNullable = null;


The problem is that DateTime is a value type. Value type can not be null.
I usually set January 1, 2000 (or any other date) as a null date and check
for it as if you would check for null.

George.
"GaryDean" <Ga******@newsgroups.nospamwrote in message
news:u7**************@TK2MSFTNGP05.phx.gbl...

Is there any good way in which to deal with null datetimes. For instance,
I can''t seem to find anything that will pass a null value in a datetime
parameter to another method. Convert.dbnull will not work for instance.
Getting nulls back and forth between C# and SQL Server is always
problematic.

--
Regards,
Gary Blakely



Sorry, I did not understand.
What is "nullable DateTime variable"?

And what is "DateTime? dtmNullable = null;"?

Can you please use it in a code maybe?

Thanks
George.
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:ON**************@TK2MSFTNGP02.phx.gbl...

"GaryDean" <Ga******@newsgroups.nospamwrote in message
news:u7**************@TK2MSFTNGP05.phx.gbl...

>Is there any good way in which to deal with null datetimes. For
instance, I can''t seem to find anything that will pass a null value in a
datetime parameter to another method. Convert.dbnull will not work for
instance. Getting nulls back and forth between C# and SQL Server is
always problematic.


Use a nullable DateTime variable e.g.

DateTime? dtmNullable = null;



这篇关于处理null和datetime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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