Emp_Course EC = new Emp_Course();
EC.Course_ID = M.Courses.Single(c => c.Course_Name == DropDownList2.Text).Course_ID;
EC.Emp_ID = M.Employees.Single(c => c.Emp_Name == DropDownList1.Text).Emp_ID;
EC.Course_Start_Date = Convert.ToDateTime(TextBox5.Text.Trim());
EC.Course_End_Date =Convert.ToDateTime( TextBox6.Text.Trim());
if (EC.Course_End_Date > EC.Course_Start_Date)
{
Response.Write("<script>alert('the end date cannot be bigger than start date')</script>");
return;
}
M.Emp_Courses.InsertOnSubmit(EC);
M.SubmitChanges();
Response.Write("<script>alert('Data Saved')</script>");
You Converted Textbox text to DateTime and then to String again and then back to DateTime. For first one you have used string format and for the end date you did not. Keep your code consistent.