关于网友提出的“datetime.compare NET中DateTime类型的空怎么表示?”问题疑问,本网通过在网上对“datetime.compare NET中DateTime类型的空怎么表示?”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题:datetime.compare NET中DateTime类型的空怎么表示?
描述: .NET中DateTime类型的空怎么表示?
现在数据库中有一个datetime类型的字段A,
如果某条记录这字段为空,SQL中可用null表示;
可是如果在.NET程序中修改其为空,该怎么写?
info.VerifyTime=null;这样肯定报错
解决方案1:
顶
解决方案2: 这里API和源码例子
一个英文的,一个翻译的:
http://apicodecn.gicp.net/class.do?api=selectByfatherIndex&father=58
http://apicode.gicp.net/class.do?api=selectByfatherIndex&father=58
解决方案3:
就这样~~
解决方案4: 不能赋值为空,因为它默认的是:0000:00:00
所以我以前做的都是让他跟他的默认值比较
解决方案5: c#中,datatime不能赋值为null, 赋值为 datetime=DBNull.Value存入数据库
从页面取值的时候可以用 DataTable date; DateTime.TryParse(数据库取出,out date);
如果取出时null。默认转换为minvalue。
解决方案6:
Nullable times=null;
解决方案7:调用这个方法看看
解决方案8: ///
/// 判断字符串为空时返回DBNull,否则返回原字符串
///
/// 字符串
///
public static object stringToObject(string str)
{
if (string.IsNullOrEmpty(str))
{
return DBNull.Value;
} else
{
return str;
}
}
解决方案9: 我一般把DateTime.MinValue 作为null
解决方案10: 使用可空类型
tyep?
解决方案11:
恩,ls说了
解决方案12: DateTime? dt = null;
解决方案13: 声明实体的时候就定义为可空类型:
public class Info
{
public DateTime? VerifyTime{get;set;}
}
就可以付空值
以上介绍了“datetime.compare NET中DateTime类型的空怎么表示?”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/2477558.html