Hi friends,
i am getting error after performing calculation and after storing data in database
The error is
formatExeption was unhandled
Input string was not in a correct format
the error is on
number2 = Convert.ToInt32(txtnumdays.Text);
the logic i have used to perform calculation is
string maxleave = "";
int number1;
int number2;
int returnValue = 0;
qry = "Select MaxLeave from LeaveMaster where LeaveName = '" + cmbLeave.Text.ToString() + "' ";
number2 = Convert.ToInt32(txtnumdays.Text);
DBCom.getData(qry);
if (DBCom.rdr.HasRows)
{
while (DBCom.rdr.Read())
{
maxleave = DBCom.rdr["MaxLeave"].ToString();
number1 = int.Parse(maxleave);
returnValue = Subtract(number1, number2);
txtLvslft.Text = returnValue.ToString();
please help how to solve this error
thanks
Loading

Santhosh Kumar JayaramanRank #563 · 4.3K reputationPosted Jul 27, 2012, 12:57 AM EDT
Int32.TryParse(txtnumdays.Text, out number2);
Atul KumarRank #1,527 · 1K reputationPosted Jul 26, 2012, 11:10 PM EDT
Ashok Kumar40 reputationPosted Jul 26, 2012, 11:19 PM EDT
i have used
string maxleave ="";
and i am converting to integer to calculate
Atul KumarRank #1,527 · 1K reputationPosted Jul 26, 2012, 11:24 PM EDT
Santhosh Kumar JayaramanRank #563 · 4.3K reputationPosted Jul 27, 2012, 12:33 AM EDT
int number2;
int returnValue = 0;
qry = "Select MaxLeave from LeaveMaster where LeaveName = '" + cmbLeave.Text.ToString() + "' ";
Int32.TryParse(txtnumdays.Text, out number2); //try this
Ashok Kumar40 reputationPosted Jul 27, 2012, 12:55 AM EDT
but the code which you given is not working fine. i have tried it
Ashok Kumar40 reputationPosted Jul 27, 2012, 1:02 AM EDT
number2 = int.TryParse(txtnumdays.Text,out number2);
the error is
Cannot implicity convert type 'bool' to 'int'
Santhosh Kumar JayaramanRank #563 · 4.3K reputationPosted Jul 27, 2012, 1:06 AM EDT
just make it as
int.TryParse(txtnumdays.Text,out number2);
remove the number2= .
The out parameter will automatically set value.
Deepak VermaRank #672 · 3.6K reputationPosted Jul 27, 2012, 1:09 AM EDT
Ashok Kumar40 reputationPosted Jul 27, 2012, 1:13 AM EDT
Int32.TryParse(txtnumdays.Text, out number2);
this is working fine
thank u