开发者

Value was either too large or too small for an Int16

I am getting below error while i am converting integer valu开发者_如何学编程e string to short from text box in .net.

Value was either too large or too small for an Int16. How can i convert ZIP code and Phone number values from text boxes? Please help me...


A 16-bit signed integer has a very small range (-32768 to 32767). In all honesty, you should not be attempting to parse them as such - just store them as string.


Expanding on @Marc and @jimmy's points:

Zip codes and phone numbers are not numbers, you don't do arithmetic with them. So just treat them as Strings. In some countries the equivalent of a Zip code is a string like this: "PA6 0UN", if you treat your zip/postal code as a string then you can cope with such "foreign" constructs.

It might be true that there is a space-saving benefit in representing a phone number as a numeric quantity, but the saving is likely to be tiny in comparison with all the rest of the data you are keeping, and processing costs of formatting and parsing will be incurred.


Agree with keeping it as a string: converting zip codes/phone numbers to a number will not bring nothing useful (who would like to sum phone numbers?)

An on the other side: phone numbers does have leading zeros (important) what would be lost by conversion to a number. Canadian zip codes contain also alphabet characters.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜