We help IT Professionals succeed at work.

Input string was not in a correct format

ghj Grandhe
ghj Grandhe asked
on
120 Views
Last Modified: 2018-09-24
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
Comment
Watch Question

AndyAinscowFreelance programmer / Consultant
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Fernando SotoRetired
CERTIFIED EXPERT
Distinguished Expert 2017
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
CERTIFIED EXPERT
Most Valuable Expert 2018
Distinguished Expert 2019
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
thanks for providing comments. i used tryparse.
Fernando SotoRetired
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
So did you find the issue?

Author

Commented:
yes, i found out that the issue is causing in int.parse and i rechanged to int.tryparse.
Fernando SotoRetired
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
That is great. Please close this question by selecting those solutions that helped.

Thanks
Fernando
AndyAinscowFreelance programmer / Consultant
CERTIFIED EXPERT

Commented:
I'd suggest you split over the first three comments.

Author

Commented:
Thanks

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions