整数值给出错误

编程入门 行业动态 更新时间:2024-10-22 21:20:08
本文介绍了整数值给出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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之间 见这里: msdn.microsoft/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: msdn.microsoft/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

更多推荐

整数值给出错误

本文发布于:2023-10-28 01:15:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1535069.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:整数   错误

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!