C# 中 bigint 的等价物是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2113526/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 23:37:10  来源:igfitidea点击:

What is the equivalent of bigint in C#?

c#.netsql-serverbigint

提问by Asad

What I am supposed to use when handling a value in C#, which is bigint for an SQL Server database?

在 C# 中处理一个值时我应该使用什么,它是 SQL Server 数据库的 bigint?

采纳答案by Patrick Karcher

That corresponds to the long(or Int64), a 64-bit integer.

这对应于long(或Int64),一个 64 位整数。

Although if the number from the database happens to be small enough, and you accidentally use an Int32, etc., you'll be fine. But the Int64will definitely hold it.

尽管如果数据库中的数字恰好足够小,并且您不小心使用了 Int32 等,您会没事的。但是Int64肯定会容纳它。

And the error you get if you use something smaller and the full size is needed? A stack overflow!Yay!

如果你使用更小的东西并且需要全尺寸,你会得到什么错误?堆栈溢出!好极了!

回答by ChaosPandion

Int64maps directly to BigInt.

Int64直接映射到BigInt.

Source

来源

回答by Otávio Décio

Use a long datatype.

使用长数据类型。

回答by John Boker

I think the equivalent is Int64

我认为等效的是 Int64

回答by Robb Sadler

I just had a script that returned the primary key of an insert and used a

我刚刚有一个脚本返回插入的主键并使用了

SELECT @@identity

on my bigint primary key, and I get a cast error using long - that was why I started this search. The correct answer at least in my case is that the type returned by that select is NUMERIC which equates to a decimal type. Using a long will cause a cast exception.

在我的 bigint 主键上,使用 long 时出现强制转换错误 - 这就是我开始此搜索的原因。至少在我的情况下,正确的答案是该选择返回的类型是 NUMERIC,它等同于十进制类型。使用 long 会导致强制转换异常。

This is one reason to check your answers in more than one Google search (or even on Stack Overflow!).

这是在不止一个 Google 搜索(甚至在 Stack Overflow 上!)中检查您的答案的原因之一。

To quote a database administrator who helped me out:

引用一位帮助我的数据库管理员的话:

... BigInt is not the same as INT64 no matter how much they look alike. Part of the reason is that SQL will frequently convert Int/BigInt to Numeric as part of the normal processing. So when it goes to OLE or .NET the required conversion is NUMERIC to INT.

We don't often notice since the printed value looks the same."

... BigInt 与 INT64 不同,无论它们看起来多么相似。部分原因是 SQL 会经常将 Int/BigInt 转换为 Numeric 作为正常处理的一部分。因此,当它转到 OLE 或 .NET 时,所需的转换是 NUMERIC 到 INT。

我们通常不会注意到,因为打印的值看起来是一样的。”

回答by Rúben

I was handling a bigint datatype to be shown in a DataGridView and made it like this

我正在处理要在 DataGridView 中显示的 bigint 数据类型,并使其像这样

something = (int)(Int64)data_reader[0];

回答by Rúben

You can use longtype or Int64

您可以使用long类型或Int64

回答by Technacron

intin sql maps directly to int32also know as a primitive type i.e intin C#whereas

INT在SQL直接映射到INT32还知道作为一个基本类型,即INTC# ,而

bigintin Sql Server maps directly to int64also know as a primitive type i.e longin C#

BIGINT在SQL服务器直接映射到Int64的,即也知道作为一个基本类型C#

An explicit conversion if biginteger to integer has been defined here

如果此处定义biginteger 到 integer 的显式转换

回答by Rajeev Sirohi

For most of the cases it is long(int64) in c#

对于大多数情况,在 c# 中它是 long(int64)

回答by Abbasibh

if you are using bigintin your database table, you can use Longin C#

如果您在数据库表中使用bigint,则可以在 C# 中使用Long