I create a database in sqlserver2017 and tried to use entity framework6 to connect the database. it's connected and I've no any errors when compiling, but I'm having some error messages like : Database.CurrentTransaction at runtime when want to create a record in the database.
/*inside the Controller*/
[HttpGet]
public ActionResult AddStudent()
{
return View();
}
[HttpPost]
public ActionResult AddStudent(Student new_stud)
{
if(ModelState.IsValid)
{
BLStudent bls = new BLStudent();
if(bls.Add(new_stud))
{
ViewBag.message = "It's recorded.";
ViewBag.color = "aqua";
}
else
{
ViewBag.message = "It's not recorded.";
ViewBag.color = "red";
}
}
else
{
ViewBag.message = "PLS enter the information correctly.";
ViewBag.color = "red";
}
return View();
}
/*inside the BLStudent Class*/
UniversityEntities db = new UniversityEntities();
public bool Add(Student new_stud)
{
try
{
db.Students.Add(new_stud);
return Convert.ToBoolean(db.SaveChanges());
}
catch (Exception)
{
return false;
}
}
Cath Exceptions :
System.Data.Entity.Infrastructure.DbUpdateException: 'An error occurred while updating the entries. See the inner exception for details.'
Inner Exceptions:
1 - UpdateException: An error occurred while updating the entries. See the inner exception for details.
2 - SqlException: The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. The statement has been terminated.
how can fix this?