社区
C#
帖子详情
有关datetime的默认值的疑问.高手看过来..
gabriel1
2004-11-25 05:36:37
如何将null值赋给一个datetime变量..
因为在c#程序中声明一个DateTime变量,它总有初始值为"0001-1-1"
请问,该怎么解决.
...全文
3281
11
打赏
收藏
有关datetime的默认值的疑问.高手看过来..
如何将null值赋给一个datetime变量.. 因为在c#程序中声明一个DateTime变量,它总有初始值为"0001-1-1" 请问,该怎么解决.
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
11 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
OriesMap
2004-11-29
打赏
举报
回复
不好意思,我借楼主的地方问自己一下各位高人,
我做的日期控件中的Value值(DateTime类型),为什么默认值总是为空,而不能象DateTimePicker一样是当前日期与时间呢?
如果默认值为当前日期与时间,DefaultValue(typeof(DateTime),"") 请问""里该怎样写,还是要为别的写法呀?
yellowhwb
2004-11-26
打赏
举报
回复
不敢相信楼主居然不知道这一点。
继承于System.ValueType的全是值(Struct)类型的:
System.ArgIterator
System.Boolean
System.Byte
System.Char
System.Collections.DictionaryEntry
System.Collections.Specialized.BitVector32
System.Collections.Specialized.BitVector32.Section
System.Configuration.Assemblies.AssemblyHash
System.Data.OracleClient.OracleBinary
System.Data.OracleClient.OracleBoolean
System.Data.OracleClient.OracleDateTime
System.Data.OracleClient.OracleMonthSpan
System.Data.OracleClient.OracleNumber
System.Data.OracleClient.OracleString
System.Data.OracleClient.OracleTimeSpan
System.Data.SqlTypes.SqlBinary
System.Data.SqlTypes.SqlBoolean
System.Data.SqlTypes.SqlByte
System.Data.SqlTypes.SqlDateTime
System.Data.SqlTypes.SqlDecimal
System.Data.SqlTypes.SqlDouble
System.Data.SqlTypes.SqlGuid
System.Data.SqlTypes.SqlInt16
System.Data.SqlTypes.SqlInt32
System.Data.SqlTypes.SqlInt64
System.Data.SqlTypes.SqlMoney
System.Data.SqlTypes.SqlSingle
System.Data.SqlTypes.SqlString
System.DateTime
System.Decimal
System.Diagnostics.CounterSample
System.Diagnostics.SymbolStore.SymbolToken
System.Double
System.Drawing.CharacterRange
System.Drawing.Color
System.Drawing.Point
System.Drawing.PointF
System.Drawing.Rectangle
System.Drawing.RectangleF
System.Drawing.Size
System.Drawing.SizeF
System.EnterpriseServices.BOID
System.EnterpriseServices.XACTTRANSINFO
System.Enum
System.Guid
System.Int16
System.Int32
System.Int64
System.IntPtr
System.IO.WaitForChangedResult
System.Reflection.Emit.EventToken
System.Reflection.Emit.FieldToken
System.Reflection.Emit.Label
System.Reflection.Emit.MethodToken
System.Reflection.Emit.OpCode
System.Reflection.Emit.ParameterToken
System.Reflection.Emit.PropertyToken
System.Reflection.Emit.SignatureToken
System.Reflection.Emit.StringToken
System.Reflection.Emit.TypeToken
System.Reflection.InterfaceMapping
System.Reflection.ParameterModifier
System.Runtime.InteropServices.ArrayWithOffset
System.Runtime.InteropServices.BIND_OPTS
System.Runtime.InteropServices.BINDPTR
System.Runtime.InteropServices.CONNECTDATA
System.Runtime.InteropServices.DISPPARAMS
System.Runtime.InteropServices.ELEMDESC
System.Runtime.InteropServices.ELEMDESC.DESCUNION
System.Runtime.InteropServices.EXCEPINFO
System.Runtime.InteropServices.FILETIME
System.Runtime.InteropServices.FUNCDESC
System.Runtime.InteropServices.GCHandle
System.Runtime.InteropServices.HandleRef
System.Runtime.InteropServices.IDLDESC
System.Runtime.InteropServices.PARAMDESC
System.Runtime.InteropServices.STATSTG
System.Runtime.InteropServices.TYPEATTR
System.Runtime.InteropServices.TYPEDESC
System.Runtime.InteropServices.TYPELIBATTR
System.Runtime.InteropServices.VARDESC
System.Runtime.InteropServices.VARDESC.DESCUNION
System.Runtime.Serialization.SerializationEntry
System.Runtime.Serialization.StreamingContext
System.RuntimeArgumentHandle
System.RuntimeFieldHandle
System.RuntimeMethodHandle
System.RuntimeTypeHandle
System.SByte
System.Security.Cryptography.DSAParameters
System.Security.Cryptography.RSAParameters
System.Single
System.Threading.LockCookie
System.Threading.NativeOverlapped
System.TimeSpan
System.TypedReference
System.UInt16
System.UInt32
System.UInt64
System.UIntPtr
System.Void
System.Web.UI.WebControls.FontUnit
System.Web.UI.WebControls.Unit
System.Windows.Forms.BindingMemberInfo
System.Windows.Forms.DataGridCell
System.Windows.Forms.LinkArea
System.Windows.Forms.Message
langmafeng
2004-11-26
打赏
举报
回复
值类型是不能赋值为null
theNull
2004-11-26
打赏
举报
回复
mark
bulong0721
2004-11-26
打赏
举报
回复
Struct(结构是不能赋予null的)
lhcoolhacker
2004-11-26
打赏
举报
回复
的确如此,我在开发论坛的时候经常碰到,目前的解决方法如下:
public DateTime pubTime;
public DateTime PubTime
{
get
{
if(pubTime.Year == "0001")
return null;
else
return pubTime;
}
}
北京的雾霾天
2004-11-26
打赏
举报
回复
只声明不给值不就是了么:)
DateTime tmpdt;
如果要是给数据库存值的话,如果数据库日期字段可以为空,则传DbNull.Value就行了.
如果只是想是不是给tmpdt给过值,这个还真的不好说.
gabriel1
2004-11-26
打赏
举报
回复
那我要不想给它初始值,该怎么办?
tonybaobao
2004-11-25
打赏
举报
回复
不行的。值类型没有null的。只有引用类型才有。
Eddie005
2004-11-25
打赏
举报
回复
不能
zhy0101
2004-11-25
打赏
举报
回复
DateTime是结构Struct不是类Class
数据库
高手
(DBA专家 ,SSIS,replacation ,tourble shooting)
...SQL Server 2008
Datetime
Cast 成 Date 类型可以使用索引(转载) 摘要: 很久没写blog,不是懒,实在是最近我这的访问速度不好,用firefox经常上传不了图片 .......今天无意发现了SQL Serv...
ASP.NET 打印、导出 【转载】
于是乎,拿
过来
好几个,相比对照之下,终于弄出来了,记录下来,以后会用得着,也给予同我一样的新手借鉴。 导出功能,还是并非我最想要的(怎么能把浏览器下载那个提示框取消了,就如同保存图片一样),有
高手
路过...
工作中使用到的单词(软件开发)_2022-06-01备份
目录 ■Java学习汇总 ■常用链接 ■2020/03/15 (最初整理 242个单词) 2020 6/28 整理 2020 6/29整理 2020 7/6整理 ...■匿名内部类,lambda表达式,JDK7新特性,等等java相关 ■2021/03/...
8. SpringBoot基础学习笔记
带着上面这些
疑问
我们就着手第一个SpringBoot程序的开发了,看看到底使用SpringBoot技术能简化开发到什么程度。 SpringBoot入门程序制作 下面让我们开始做第一个SpringBoot程序吧,本课程基于Idea2020.3版本...
ASP.NET 打印、导出
导出功能,还是并非我最想要的(怎么能把浏览器下载那个提示框取消了,就如同保存图片一样),有
高手
路过,请指点一二...... ************导出GridView数据************<br
C#
110,533
社区成员
642,574
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章