整数值给出错误 [英] integer value give error

查看:114
本文介绍了整数值给出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

objdal.Name1 = txt_name.Text;
objdal.Address= txt_address.Text;
objdal.Mob =Convert.ToInt32(txt_mob.Text);





i代码隐藏文件中包含此代码。





i have this code in codebehind file.

cmd.Parameters.AddWithValue("@name1", Name1);
cmd.Parameters.AddWithValue("@address",Address);
cmd.Parameters.AddWithValue("@mob_no", Mob_no);



DAL文件中的此代码。





这里我把mob no作为int datatype.But错误就是这样...

System.OverflowException:Value是要么对于Int32而言太大或太小。



在我的代码中我做错了什么?


this code in DAL file.


here i have take mob no as int datatype.But error is comming like this...
System.OverflowException: Value was either too large or too small for an Int32.

what i have do wrong in my code?

推荐答案

你好



Int32取值介于2,147,483,647和-2,147,483,648之间



见这里:

< a href =http://msdn.microsoft.com/en-us/library/system.int32.aspx> http://msdn.microsoft.com/en-us/library/system.int32.aspx [ ^ ]



如果你的值超出这个范围,它会在尝试将它转换为int32时抛出此异常。



Valery。
Hello

Int32 takes a value between 2,147,483,647 and -2,147,483,648

See here:
http://msdn.microsoft.com/en-us/library/system.int32.aspx[^]

If your value falls out of this range it will throw this exception while trying to convert it to int32.

Valery.


System.OverflowException:对于Int32,值太大或太小

如你所说,你是使用电话号码,很可能它比Int32可以处理的大。



对于 Int32 ,以下是价值范围:2,147,483,647,(因此作为电话号码: (214)748-3647)。以上任何内容都会引发异常。



要存储电话号码,请使用 Int64 bigint long 。如果适合你,甚至字符串也会这样。
System.OverflowException: Value was either too large or too small for an Int32
As you said, you are using phone number for it, most probably it is too large from what an Int32 can handle.

For Int32, following is the range of value: 2,147,483,647, ( thus as a phone number: (214) 748-3647 ). Anything above that will throw the exception.

For storing a phone number, either use a Int64, bigint or long. Even string would do if that fits in for you.


int32只能容纳31位的数字(另一位用于显示该值是正数还是负数)

这意味着如果您的手机号码大于2147483647,则不适合整数。您可以使用一个长64位,但我会将所有电话号码存储为字符串,以便他们可以保留国际号码表示+



编辑:错字:男孩为位 - 愚蠢的预测文本! - OriginalGriff
An int32 can only hold numbers that fit in 31 bits (the other bit is used to show if the value is positive or negative)
Which means that if you mobile number is larger than 2147483647 it won''t fit in an integer. You could use a long which holds 64 bits, but I would store all phone numbers as strings so that they could potentially hold the International number indicate, "+"

typo: "boys" for "bits" - stupid predictive text! - OriginalGriff


这篇关于整数值给出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆