I am getting the value of a datetime picker and add it in the database but it is throwing an exception saying :
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime.
The statement has been terminated.
This is my SQL Statement
public bool AddStaff(Staff s)
{
bool StaffUnique = IsUnique(s);
if (StaffUnique)
{
try
{
conn.Open();
SqlCommand comm = new SqlCommand("INSERT INTO tblStaff VALUES ('" + s.IDCardNumber + "','" + s.FirstName + "','" + s.LastName + "','" + s.DateOfBirth + "','" + s.Gender + "','" + s.Address1 + "','" + s.Address2 + "','" + s.TownID + "','" + s.PostalCode + "','" + s.JobTypeID + "','" + s.DateOfEmployment + "','" + s.Email + "','" + s.TelephoneNumber + "','" + s.MobileNumber + "')", conn);
comm.ExecuteNonQuery();
return true;
}
catch (Exception e)
{
MessageBox.Show(e.Message.ToString());
return false;
}
finally
{
conn.Close();
}
}
else
{
return false;
}
}
Pls help if you have a solution.