FormatingException was Handled

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • geethaselvin
    New Member
    • Oct 2012
    • 1

    FormatingException was Handled

    Error : Input string was not in a correct format.

    Code:
    public partial class frmDealerForm : Form
        {
            DataTable t;
            DataRow r;
            string id;
            private void btnNew_Click(object sender, EventArgs e)
            {
                txtdealerID.ResetText();
                txtname.ResetText();
                txtaddress.ResetText();
                txtphoneno.ResetText();
                try
                {
                    int ctr, len;
                    string codeval;
                    t = kalliskaBillingDataSet.Tables["DealerDetail"];
                        len = t.Rows.Count - 1;
                        r = t.Rows[len];
                        id = r["DealerID"].ToString();
                        codeval = id.Substring(1, 3);
           [B] //Input string was not in a correct format                    
            ctr = System.Convert.ToInt32(codeval);       [/B]                    
                       if ((ctr >= 1) && (ctr < 9))
                        {
                            ctr = ctr + 1;
                            txtdealerID.Text = "DE00" + ctr;
                            txtdealerID.Enabled = false;
                        }
                        else if ((ctr >= 9) && (ctr < 99))
                        {
                            ctr = ctr + 1;
                            txtdealerID.Text = "DE0" + ctr;
                            txtdealerID.Enabled = false;
                        }
                        else if (ctr >= 99)
                        {
                            ctr = ctr + 1;
                            txtdealerID.Text = "DE" + ctr;
                            txtdealerID.Enabled = false;
                        }
                    }
                
                catch (IndexOutOfRangeException)
                {
                    txtdealerID.Text = "DE00";
                }
                btnNew.Enabled = true;
            }
    Attached Files
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Put a break point on line 22 in the above posted code to determine what your substring is returning. It sounds like it's not returning a number.

    Comment

    Working...