如何将sqlserver的bigint转换为int? [英] how to convert bigint of sqlserver into int?

查看:1544
本文介绍了如何将sqlserver的bigint转换为int?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,先生,
如何将电话号码存储到数据库中?
先生,我在sql中使用数据类型bigint在asp.net中使用int的电话号码字段,而当我从前端给出值时却给出了异常. 将bigint转换为int时出错" .

谢谢...

Hi Sir,
how to store the phone number into the database?
sir, I have taken phone number field of datatype bigint in sql and int in asp.net than when I am giving value from frontend it is giving exception .i.e; "Error in converting bigint to int".

Thank you...

推荐答案

bigint数据类型遵循与int数据类型相同的规则和原则,不同之处在于其字段可以容纳从-9,223,372,036,854,775,808到9,223,372,036,854,775,807.它在某种程度上等效于C ++''长整数,但更精确地等效于.NET Framework的System.Int64数据类型.
您还可以将此数据类型应用于将容纳(非常)大数字的列.与此数据类型等效的.NET Framework数据库是位于System.Data.SqlTypes
中的SqlInt64类. SqlDbType.BigInt的.NET等效值为Int64(长整数),因此您可以使用Convert.ToInt64long类型.
The bigint data type follows the same rules and principles as the int data type except that its field can hold numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. It is somehow equivalent to the C++'' long integer but more accurately equivalent to the .NET Framework''s System.Int64 data type.
you can also apply this data type for a column that would hold (very) large numbers. The .NET Framework database equivalent to this data type is the SqlInt64 class which resides in System.Data.SqlTypes
The .NET equivalent of SqlDbType.BigInt is Int64 (long) so You can use Convert.ToInt64 and long type.


除了我以前的解决方案之外,该基于Shristi注释的解决方案

嘿, Shristi 我已经创建了一个表格
In addition to my previous solution this solution based on Shristi Comments

Hey, Shristi I''ve created a table
create table address(name varchar(25),pno bigint)


您可以看到我已经将pno [PhoneNo]用作bigint数据类型
并使用以下代码保存数据,效果更好,并且成功保存了数据


you can see I''ve used pno[PhoneNo] as bigint datatype
and saved data by using below code it works better and saving data successfully

SqlConnection con = new SqlConnection("Database Connection String");
            con.Open();
            SqlCommand cmd = new SqlCommand("insert into address values(@name,@pno)", con);
            cmd.Parameters.Add(new SqlParameter("@name",SqlDbType.VarChar,25));
            cmd.Parameters["@name"].Value = textBox1.Text;
            cmd.Parameters.Add(new SqlParameter("@pno",SqlDbType.BigInt));
            cmd.Parameters["@pno"].Value = Convert.ToInt64(textBox2.Text);
            cmd.ExecuteNonQuery();            


希望 [ ^ ]可能会为您提供帮助.
Hope this[^] might help you.


这篇关于如何将sqlserver的bigint转换为int?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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