I am getting the following error when trying to save registration date in the database. The conversion of a varchar data type to a datetime data type resulted in an out-of-range value. The statement has been terminated.
[WebMethod]
public bool Attendance(Attendance attendance)
{
bool UploadSuccess = false;
cn.Open();
SqlCommand com = new SqlCommand("INSERT INTO tblAttendance (StudentID, RegistrationDate) values (" +
attendance.StudentID + " ,'" +
attendance.RegistrationDate + "')", cn);
{
com.Parameters.AddWithValue("@StudentID", attendance.StudentID);
com.Parameters.AddWithValue("@RegistrationDate", attendance.RegistrationDate);
int i = com.ExecuteNonQuery();
cn.Close();
if (i != 0)
{
UploadSuccess = true;
}
return UploadSuccess;
}
}
I am trying to save the current date after the students have successfully registered
Attendance record = new Attendance();
record.StudentID = a.StudentID;
record.RegistrationDate = DateTime.Now;