k001..k002,k003
error:::
Input string was not in a correct format.
cn.open();
int r;
string str = "select MAX(empcode) from tbl_organization1";
MySqlCommand cmd = new MySqlCommand(str, cn);
MySqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
string a = dr[0].ToString();
if (a == "")
{
lblempcode.Text = "K" + 001;
}
else
{
string v = a.TrimStart('K');
r = Convert.ToInt32(v);
r = r + 1;
string strtt = "K" + string.Format("{0:000}",r); ;
lblempcode.Text = strtt.ToString();
// = strtt + 1;
}
cn.Close();
}
}
ancy chackoPosted Feb 18, 2015, 1:19 AM
Khargesh RajputPosted Feb 18, 2015, 1:12 AM
here you are converting string 'K' to integer,
is this possible to convert string to an integer
Prasham SabadraPosted Feb 18, 2015, 1:09 AM
This error may be @ line r = Convert.ToInt32(v);. Rather than using Convert.ToInt32 please try using Int32.TryParse method.
Reference : https://msdn.microsoft.com/en-us/library/f02979c7(v=vs.110).aspx