Problem I have is that the following code works only if the user tabs out of the field, (or moves the cursor to another field in the same form), if the cursor is still at the end of the date text, none of the error traps catch, but I get an exception when updating the database. SQL Server 2008. Visual Studio 3.5 SP1.
Routine AddParams adds the Parameter @JoinDate and its value to the Update command
if (txtCompanyJoinDate.Text.Trim() != "")
{
if (!DateTime.TryParse(txtCompanyJoinDate.Text, out dtTestDate))
MessageBox.Show("Invalid Format NOT Updated", "Company Join Date");
else
{
if (c1.CheckSqlDate(dtTestDate) == false)
MessageBox.Show("SQL Date Conversion Error", "Company Join Date");
else
AddParams("CompanyJoinDate", "@JoinDate", dtTestDate);
}
}
public Boolean CheckSqlDate(DateTime dt0)
{
return ((dt0 <= System.Data.SqlTypes.SqlDateTime.MaxValue.Value)
&& (dt0 >= System.Data.SqlTypes.SqlDateTime.MinValue.Value));
}