.ToString("yyyy-MM-dd"); ((DateTime)dt.Rows[0]["Request_Date"]).ToString("yyyy-MM-dd");当Request_Date在数据库中为null的时候,怎么处理 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 先做判断!=null时再进行格式转换 if(Request_Date!=null){ ((DateTime)dt.Rows[0]["Request_Date"]).ToString("yyyy-MM-dd");} (dt.Rows[0]["Request_Date"]) == null ? Convert.ToDateTime(dt.Rows[0]["Request_Date"]) : Convert.ToDateTime(dt.Rows[0]["Request_Date"]).ToString("yyyy-MM-dd"); dt.Rows[0]["Request_Date"]就为null了也不要用(DateTime)进行格式转换 if(dt.Rows[0]["Request_Date"]!=null){ strDate = ((DateTime)dt.Rows[0]["Request_Date"]).ToString("yyyy-MM-dd");}else{//这里写为NULL时 你要做什么} (dt.Rows[0]["Request_Date"]) == null ? Convert.ToDateTime(dt.Rows[0]["Request_Date"]) : Convert.ToDateTime(dt.Rows[0]["Request_Date"]).ToString("yyyy-MM-dd");恩。比较好。 还可以直接写到前台 。。很方便 改用DataReader去读或者先判断dt.Rows[0]["Request_Date"] == DBNull.Value ? string.Empty : ((DateTime)dt.Rows[0]["Request_Date"]).ToString("yyyy-MM-dd") visual studio 2010 数据库连接配置 百度搜索 asp.net 如何获取一个table里面的内容 如何实现按姓氏笔画数排序 高手来看一下 怎么把网站之间的文件夹相互同步 ASP.NET 2.0 高级编程(第4版) 如何在脚本中获取gridview中绑定的下拉列表控件的代码值? 最后10分,帮帮忙 关于VS2003和VS2005开发工具冲突的一个问题 ASP.NET中常用的三十三种代码 asp.net + wcf超级疑难
先做判断!=null时再进行格式转换
{
((DateTime)dt.Rows[0]["Request_Date"]).ToString("yyyy-MM-dd");
}
dt.Rows[0]["Request_Date"]就为null了也不要用(DateTime)进行格式转换
{
strDate = ((DateTime)dt.Rows[0]["Request_Date"]).ToString("yyyy-MM-dd");
}
else
{
//这里写为NULL时 你要做什么
}
恩。比较好。
还可以直接写到前台 。。很方便
或者先判断
dt.Rows[0]["Request_Date"] == DBNull.Value ? string.Empty : ((DateTime)dt.Rows[0]["Request_Date"]).ToString("yyyy-MM-dd")