title: How to resolve Format Exception Error in asp.net?
body: <p>I am getting this error while debugging.</p>
  
  <blockquote>
    <p>when converting a string to date time object parse the string to take
    the date before putting each variable in the date time object</p>
  </blockquote>
  
  <p>Can any one suggest me a solution for how to resolve it?</p>
  
  <pre><code> protected void btnSubmit_Click(object sender, EventArgs e)
      {
          var employeeid = PayrollHelper.Context.Payroll_PersonalDetails.Where(a =&gt; a.Employee_Code == txtEmployCode.Text).Select(a =&gt; a.Employee_id).First();
          var source = PayrollHelper.Context.Payroll_SalaryDetails.Where(a =&gt; a.fkEmployee_ID == Convert.ToInt32(employeeid) &amp;&amp; a.SalaryOfMonth.Value.Month == Convert.ToDateTime(lbMonth.Text).Month).Select(a =&gt; a);
  
          if (source.Count() == 0)
          {
              var Count = PayrollHelper.Context.Payroll_AdvanceManagements.Where(a =&gt; a.fkEmployee_ID == employeeid).Select(a =&gt; a);
              if (Count.Count() != 0)
              {
                  var salary_ad = PayrollHelper.Context.Payroll_AdvanceManagements.Where(a =&gt; a.fkEmployee_ID == employeeid).Select(a =&gt; a).First();
                  if ((salary_ad.Salary_Advance &gt; salary_ad.Refund_Advance) &amp;&amp; txtAdvanceDeduction.Text != "")
                  {
                      salary_ad.Refund_Advance = salary_ad.Refund_Advance + Convert.ToDecimal(txtAdvanceDeduction.Text);
                      PayrollHelper.Context.SubmitChanges();
                      Payroll_AdvanceRefundBL obj = new Payroll_AdvanceRefundBL(Convert.ToDecimal(txtAdvanceDeduction.Text), DateTime.Now, employeeid);
  
                      if (obj.Insert())
                      {
  
                      }
                  }
              }
  
              bool cl = false;
              if (ViewState["cl"] != "")
              {
                  cl = true;
              }
              Payroll_SalaryDetailBL obj1 = new Payroll_SalaryDetailBL(Convert.ToDecimal(Math.Round(Convert.ToDecimal(lbPay.Text), 2)), Convert.ToSingle(Math.Round(Convert.ToDouble(txtGeneralWorkingDays.Text), 2)), Convert.ToSingle(Math.Round(Convert.ToDouble(lbNumberDay.Text), 2)), Convert.ToDecimal(lbInsentive.Text), Convert.ToString(Math.Round(Convert.ToDecimal(lbExtraHour.Text), 2)), Convert.ToDecimal(Math.Round(Convert.ToDecimal(lbBenifit.Text), 2)), Convert.ToDecimal(Math.Round(Convert.ToDecimal(txtInvolument.Text), 2)), Convert.ToDecimal(Math.Round(Convert.ToDecimal(lbGross.Text), 2)), Convert.ToDecimal(Math.Round(Convert.ToDecimal(lbBasic.Text), 2)), Convert.ToDecimal(Math.Round(Convert.ToDecimal(lbHRA.Text), 2)), Convert.ToDecimal(Math.Round(Convert.ToDecimal(lbCridtTotal.Text), 2)), Convert.ToDecimal(Math.Ceiling(Convert.ToDouble(lbNett.Text))), Convert.ToDecimal(Math.Round(Convert.ToDecimal(lbSalaryAd.Text), 2)), Convert.ToDecimal(Math.Round(Convert.ToDecimal(txtAdvanceDeduction.Text), 2)), Convert.ToDecimal(Math.Round(Convert.ToDecimal(lbPF.Text), 2)), Convert.ToDecimal(Math.Round(Convert.ToDecimal(lbESI.Text), 2)), Convert.ToDecimal(Math.Round(Convert.ToDecimal(lbDeductionTotal.Text), 2)), Convert.ToDateTime(txtSalaryDate.Text).AddMonths(-1), cl, Convert.ToInt32(employeeid));
              if (obj1.Insert())
              {
  
              }
          }
  
  
  }
  </code></pre>