Ashok Kumar

Ashok Kumar

  • NA
  • 38
  • 45.9k

error message is not showing for datetime picker

Aug 10 2012 3:03 AM
hi friends,
    i create leave approval application in windows form application i have taken two datetime pickers only i have chose date in property.
my problem is i have created a button in that button i have wrote conditon to datetime picker to show error message" please select the date" but when i click button with out selecting datetime picker the date is storing. This is because the datetime picker is taking default current date 
plese could any one help how to solve this problem
my code is this
 if (txtEmpCode.Text == "")
            {
                errorMsg("Please Enter The Employee Code");
                txtEmpCode.Focus();
            }

            else if (cmbLeave.Text == "--Select--")
            {
                errorMsg("Please select leavetype");
                cmbLeave.Focus();
            }


        // else if (DateTime.TryParse(dtpToDate.Text, out SelectedDate))
      
        //else if (DateTime.TryParseExact("12/12/2012", Format, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out SelectedDate))
        else if (dtpToDate.Text =="")
            {
                errorMsg("Please Enter The todate");
                dtpToDate.Focus();
            }
            
            else if (Convert.ToDateTime(dtpFromDate.Text) > Convert.ToDateTime(dtpToDate.Text))
            {
                errorMsg("From date cannot be greater than To date");
                dtpToDate.Focus();
            }
   else
            {


                qry = "Select LeaveCode from LeaveMaster where LeaveName='" + cmbLeave.Text.Trim().ToString() + "'";
                DBCom.getData(qry);
                if (DBCom.rdr.HasRows)
                {
                    while (DBCom.rdr.Read())
                    {
                        LeaveCode = DBCom.rdr["LeaveCode"].ToString();
                    }
                }
tell me how to solve many i have given some suggestion but that are not working which i have tried i mention in // comments. The code which i have mentioned in // comments is working when i click button but after selecting the datetime picker also it is showing please select to date
could any one solve this problem

thanks