C# 中的 bigint 相当于什么?

发布于 2024-08-18 16:59:08 字数 56 浏览 5 评论 0原文

在处理 C# 中的值(对于 SQL Server 数据库来说是 bigint)时,我应该使用什么?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

只涨不跌 2024-08-25 16:59:08

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

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

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

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

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 Int64 will definitely hold it.

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

病毒体 2024-08-25 16:59:08

Int64 直接映射到 BigInt

来源

Int64 maps directly to BigInt.

Source

北座城市 2024-08-25 16:59:08

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

SELECT @@identity

在我的 bigint 主键上使用 a ,并且使用 long 得到了强制转换错误 - 这就是我开始此搜索的原因。正确的答案,至少在我的例子中,是该选择返回的类型是 NUMERIC,它相当于十进制类型。使用 long 将导致强制转换异常。

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

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

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

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

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.

This is one reason to check your answers in more than one Google search (or even on 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.

笨笨の傻瓜 2024-08-25 16:59:08

使用长数据类型。

Use a long datatype.

隐诗 2024-08-25 16:59:08

您可以使用long类型或Int64

You can use long type or Int64

情感失落者 2024-08-25 16:59:08

我认为相当于 Int64

I think the equivalent is Int64

遇见了你 2024-08-25 16:59:08

sql 中的 int 直接映射到 int32 也称为原始类型,即 C# 中的 int

bigint Sql Server 中的 直接映射到 int64 也称为原始类型,即 C# 中的 long

如果 biginteger 到整数具有显式转换已在此处定义

int in sql maps directly to int32 also know as a primitive type i.e int in C# whereas

bigint in Sql Server maps directly to int64 also know as a primitive type i.e long in C#

An explicit conversion if biginteger to integer has been defined here

别挽留 2024-08-25 16:59:08

我设法使用 Convert.ToInt64 转换从数据库返回的 (bigint) 值。

IE

var Id = Convert.ToInt64(identityAsTable.Rows[0].Field<object>(0));

I managed to convert the (bigint) value returned from the DB using Convert.ToInt64.

ie

var Id = Convert.ToInt64(identityAsTable.Rows[0].Field<object>(0));
比忠 2024-08-25 16:59:08

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

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

后eg是否自 2024-08-25 16:59:08

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

if you are using bigint in your database table, you can use Long in C#

酒几许 2024-08-25 16:59:08

int(64) 或 long 数据类型相当于 BigInt。

int(64) or long Datatype is equivalent to BigInt.

ゝ杯具 2024-08-25 16:59:08

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

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

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

something = (int)(Int64)data_reader[0];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文