I have a C# window application to fill in Date of Birth and send the data to my database with type datetime. Here is the code:
DateTime dateOfBirth;
try
{
dateOfBirth = new DateTime(int.Parse(textBox54.Text), int.Parse(textBox53.Text), int.Parse(textBox52.Text));
}
catch (Exception ex)
{
MessageBox.Show("Invalid");
return;
}
It works fine with proper date, but when I randomly test my application and fill in "234" for Year, datetime from varchar conversion out of range error occurs in the statement
cm.ExecuteNonQuery();
How can I catch it? Thanks.