Link to home
Start Free TrialLog in
Avatar of ghj Grandhe
ghj Grandhe

asked on

Input string was not in a correct format

Getting Input String Was not in a correct Format
.Actually I had written a method in webservice as method name as caculator
 [WebMethod]
   public int caculator(int firstNumber,int secondNumber,string operation)
    {
        int result = 0;
        switch(operation)
        {
            case "+": result = firstNumber + secondNumber;
                break;
            case "-": result = firstNumber - secondNumber;
                break;
            case "*": result = firstNumber * secondNumber;
                break;
            case "/":result = firstNumber / secondNumber;
                break;
        }
        return result;
    }
and Iam consuming this in webapplication where I have written as
private void BindData()
        {
            string operation = txtOperation.Text;
            WebService1 objWebService = new WebService1();
            int result=objWebService.caculator(int.Parse(txtFirstNumber.Text), int.Parse(txtSecondNumber.Text), operation);
            if (result != 0)
                Response.Write(result);
        }
 in this iam getting error at this line
int result=objWebService.caculator(int.Parse(txtFirstNumber.Text), int.Parse(txtSecondNumber.Text), operation);

i doesn't understand why iam getting error here. Even though i converted it into string
could you please suggest as soon as possible
SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ghj Grandhe
ghj Grandhe

ASKER

thanks for providing comments. i used tryparse.
So did you find the issue?
yes, i found out that the issue is causing in int.parse and i rechanged to int.tryparse.
That is great. Please close this question by selecting those solutions that helped.

Thanks
Fernando
I'd suggest you split over the first three comments.
Thanks