Monday, May 24, 2010

Convert string into integer with error in c#?

I have following script try to convert string to int64


Int64 MyCompanyID1 = Convert.ToInt64(MyCompany1);


which MyCompanyID1 is string contain "123"


but I get error: Input string was not in a correct format, so I changed to another script:


long MyCompanyID1 = Convert.ToInt64(MyCompany1);


I got same error, any help please? Thanks,

Convert string into integer with error in c#?
My guess is that there are some hidden characters in your string that you are not seeing. Are you sure your string is reallly "123" or are you grabbing it from another function call or input. You can easily tests this by simply setting


MyCompany1 = "123";


then running your convert. It works fine on my end. good luck!
Reply:MyCompanyID1 can't be a string containing "123", because you've already declared it as an integer.

sweet pea

No comments:

Post a Comment