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 JayaramanPosted Jul 27, 2012, 4:57 AM
Int32.TryParse(txtnumdays.Text, out number2);
Ashok KumarPosted Jul 27, 2012, 5:13 AM
Int32.TryParse(txtnumdays.Text, out number2);
this is working fine
thank u
Deepak VermaPosted Jul 27, 2012, 5:09 AM
Santhosh Kumar JayaramanPosted Jul 27, 2012, 5:06 AM
just make it as
int.TryParse(txtnumdays.Text,out number2);
remove the number2= .
The out parameter will automatically set value.
Ashok KumarPosted Jul 27, 2012, 5:02 AM
number2 = int.TryParse(txtnumdays.Text,out number2);
the error is
Cannot implicity convert type 'bool' to 'int'
Ashok KumarPosted Jul 27, 2012, 4:55 AM
but the code which you given is not working fine. i have tried it
Santhosh Kumar JayaramanPosted Jul 27, 2012, 4:33 AM
int number2;
int returnValue = 0;
qry = "Select MaxLeave from LeaveMaster where LeaveName = '" + cmbLeave.Text.ToString() + "' ";
Int32.TryParse(txtnumdays.Text, out number2); //try this
Atul KumarPosted Jul 27, 2012, 3:24 AM
Ashok KumarPosted Jul 27, 2012, 3:19 AM
i have used
string maxleave ="";
and i am converting to integer to calculate
Atul KumarPosted Jul 27, 2012, 3:10 AM