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;
}
Comment