事先检查了sql的字段类型,可以为空,好的,我们跳过这个问题;
看了一下 SqlParameter[] GetParam存储sql数据的语句,System.Data.SqlDbType.DateTime,类型也没有错,跳过;
然后我把GetParam的内容判断一下 param[5].Value = info.SP_ApprpveTime == null ? (DateTime?)null : Convert.ToDateTime(info.SP_ApprpveTime);无可奈何还是不行;
去实体类info那里看一下, public DateTime ApprpveTime { get; set; }
ok,好像发现问题所在了!!!.NET2.0以上版本Datetime类型和Datetime?类型是有所区别的!!!Datetime类型不能为空,而Datetime?类型是可以为空的!!
解决方案:
实体类: public DateTime? 字段名{ get; set; }
SQLHelper:param[5].Value = (info.字段名 == DateTime.MinValue || info.字段名 == null) ? (DateTime?)null : Convert.ToDateTime(info.字段名);