Answered by:
Value was either too large or too small for an Int32

Question
-
User-542418535 posted
I know this is a dumb question but please bear with with me. I have a textbox called txtTelNumber which will display the phone number entered into the textbox. When running the program, it stopped at this line:
int TelNumber = Int32.Parse(txtBoxTelNumber.Text);
and showed this error: "Value was either too large or too small for an Int32."
I am puzzled of this. The txtTelNumber max length is set to 10.
Monday, May 13, 2013 6:24 PM
Answers
-
User-1716253493 posted
http://msdn.microsoft.com/en-us/library/06bkb8w2(v=vs.71).aspx
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, May 13, 2013 6:53 PM
All replies
-
User1508394307 posted
Why do you want to save phone number in integer variable? Maximum for int is 2147483647, so it cannot be used for 10-digit numbers bigger than 2147483647.
Monday, May 13, 2013 6:28 PM -
User-542418535 posted
Yeah that totally makes sense. Which data type would be best to store a phone number in?
Monday, May 13, 2013 6:41 PM -
User-1716253493 posted
http://msdn.microsoft.com/en-us/library/06bkb8w2(v=vs.71).aspx
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, May 13, 2013 6:53 PM -
User1508394307 posted
Yeah that totally makes sense. Which data type would be best to store a phone number in?
string for c#, varchar(10) for your database.
Monday, May 13, 2013 7:14 PM -
User465171450 posted
If you have international phone numbers, you will need more than 10 string characters since international numbers also need a country code.
Tuesday, May 14, 2013 12:08 AM -
User1508394307 posted
In this case, the txtTelNumber max length must be changed too.
Tuesday, May 14, 2013 2:26 AM -
User-1800438376 posted
try this,
long TelNumber = Int64.Parse(txtBoxTelNumber.Text);
Tuesday, May 14, 2013 4:40 AM