我有例外:空值不能被分配到一个成员类型的System.DateTime
The null value cannot be assigned to a member with type System.DateTime which is a non-nullable value type.
Source Error:
var bd = (from d in baza.hpurs where d.userID == userID && d.date !=null select d.date).Max();
我的方法:
public ActionResult Add_hours(int userID)
{
var dat = DateTime.Today;
var bd = (from d in baza.hours where d.userID == userID && d.date !=null select d.date).Max();
if (bd != dat)
{
return View();
}
else
{
var dd = (from d in baza.hours where d.userID == userID && d.date == dat select d.hoursID).Single();
return RedirectToAction("hours_is", "Employer", new { HoursID = dd });
}
}
它的工作原理很好,但只有当我有1个或多个以小时表格为具体用户的数据。 这个错误是当我想添加几小时到具体用户没有添加任何小时的表格。 我没有任何想法如何修复它...
非常感谢。是工作。 – user1031034
非常感谢你 –
感谢您的解释,让我有点疯狂,试图找到愚蠢的解决方法。 – Yablargo