int.parse

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi to all
i have
string y;
int x=int.parse(y);
when i run the application this exeption is trewn
///////////////////////////////////////
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct
format.

Source Error:

Line 106: string Bind=txtBimsID.Text.ToString();
Line 107: //////////////////////////////////
Line 108: int Ax=int.Parse(y);

Plz any help
Thanks
 
sara said:
Hi to all
i have
string y;
int x=int.parse(y);
when i run the application this exeption is trewn
///////////////////////////////////////
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct
format.

Source Error:

Line 106: string Bind=txtBimsID.Text.ToString();
Line 107: //////////////////////////////////
Line 108: int Ax=int.Parse(y);

Plz any help
Thanks

What is the value of string "y"? The error says that it
doesn't look like a correct number.

Just a sidenote: The "Text" property of (I'm guessing) a TextBox
already gives a string value. No need to use ToString() there.
 
Thanks Hans
let say y=4;

Hans Kesting said:
What is the value of string "y"? The error says that it
doesn't look like a correct number.

Just a sidenote: The "Text" property of (I'm guessing) a TextBox
already gives a string value. No need to use ToString() there.
 
y can't be = 4 because it's a string....

if y = "4"; then Int.Parse(y) should work...so it's probably something
other than "4"

Karl
 
From where comes y ?

You get the text in the Bind variable but you try to parse y ???

Patrice
 
Ansil

Convert.ToInt32 calls Int32.Parse

public sealed class Convert
{
public int ToInt32( string value )
{
if ( value == null ) return 0;
return Int32.Parse( value );
}
}

bill
 
In addition, other characters in the string may also mess up the parsing.
For instance, suppose that you have y=" 4 ". Although that does look like
the number four, it has spaces around it which might cause parse problems.
If the user is entering this information in a textbox, then you might assume
the data is bad since the user could enter anything and you might have to
clean it up before parsing it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top