2

Exception

I am getting an exception in that line. My coding is correct yet still I am getting an error. Can anyone help me to rewrite the code for that particular line. I am using that line for viewing of a value from the database to textbox. getprogress is method name from webservice.

5
  • 1
    What is in the value of menuitemno.Text? Commented May 23, 2012 at 7:25
  • am giving 1 as input..but all textbox filled by 0 zeros Commented May 23, 2012 at 7:26
  • 1
    Okay, so when you put a breakpoint on that line, could paste the exact value of menuitemno.Text? Commented May 23, 2012 at 7:28
  • no..where ever am keeping breakpoint also am getting same error.. Commented May 23, 2012 at 7:31
  • am gettng error if am giving convert.toduble("32.64") Commented May 23, 2012 at 8:43

6 Answers 6

1

use int.TryParse()

int result;
if(int.TryParse( menuitemno.Text, out result))
   progress = web.getprogress(result);
else
   //You have incorrect integer in menuitemno.Text
Sign up to request clarification or add additional context in comments.

Comments

1

The value of menuitemno.Text is like 32.64 (having decimal), so it is not possible to convert decimal to integer using convert.toint.

Use Convert.ToInt64(Convert.ToDouble(menuitemno.Text)) for conversion.

To do this discounting rounding you could do:

Convert.ToInt64(Math.Floor(Convert.ToDouble(menuitemno.Text)));

If you need to round you could replace Math.Floor with Math.Round.

Convert.ToInt64(Math.Round(Convert.ToDouble(menuitemno.Text)));

if value of menuitemno.Text is empty or has invalid char than also the error may come.

If you are now allowing decimal place in the menuitemno.Text then use Int64.TryParse

Comments

0

It seems menuitemno is not a valid string which can be converted to integer. Just check the value of menuitemno.Text, I suspect it does not have an integer value. Right click to "menuitemno.Text" and select quick watch; it will show the value.

Comments

0

the value of the text box, most probabbly i null or empty, to fix this issued, assuming that those values are in the range of acceptable ones, you can do:

int i =0; 
int.TryParse(menuitemno.Text, out i);
progress = i;

Something like this.

Comments

0

Is menuitemno a textbox? You should rather use a numericupdown if it only accepts numbers. That way you won't have to convert to a number and you can apply restriction, such as no decimal places allowed, quite easily.

Comments

0

No need to parse any integer value, when using RadTextBox

Hashtable newval = new Hashtable();
int Age = Convert.ToInt32(newval["Age"].ToString());

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.