我有这个linq查询,即使我将DateTime设置为DBNullable,它仍然返回此错误。跟踪指示从数据库返回的insertdate和Deletedate值是问题。
这是错误:
在System.DBNull.System.IConvertible.ToDateTime(IFormatProvider提供程序)
在System.Convert.ToDateTime(对象值)
public DateTime? insertDate { get; set; }
public DateTime? deleteDate { get; set; }
public List<Parameters> fraudResults(DataTable dt)
{
var convertedList = (from rw in dt.AsEnumerable()
select new Parameters()
{
ID = Convert.ToInt32(rw["ID"]),
retailer = Convert.ToString(rw["Retailer"]),
flaggedReason = Convert.ToString(rw["FlaggedReason"]),
insertDate = Convert.ToDateTime(rw["InsertDate"]),
deleteDate = Convert.ToDateTime(rw["DeleteDate"])
}).ToList();
return convertedList;
}
任何帮助将不胜感激。
答案 0 :(得分:1)
尝试
rw [“ InsertDate”] == DbNull.Value吗? null:Convert.ToDateTime(rw [“ InsertDate”]。ToString());