views:

909

answers:

5

Hi, what I am suppose to use when handling a value in c#, which is bigint SQLSERVER DB ?

Thanks

+11  A: 

Int64 maps directly to BigInt.

Source

ChaosPandion
Thanks mate. It is faster to ask a question here get an answer than going over to MSDN and banging your head!!!
Asad Butt
No problem I wish they would be more specific with the names.
ChaosPandion
hang on, its strange, I have a bigint in DB, but when I try to access that coulmn / property with the object it shows it as long, why not Int64 ?
Asad Butt
is long other name for Int64 /
Asad Butt
Yes. The `long` keyword is an alias for `System.Int64`.
Anon.
Don't forget to accept so your percentage doesn't drop.
ChaosPandion
+1  A: 

Use a long datatype.

Otávio Décio
+5  A: 

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

Although if the number from the db 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? Stack Overflow!!! Yay!!!!!!!

Patrick Karcher
A: 

I think the equivalent is Int64

John Boker
A: 

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

SELECT @@identity

on my bigint PK 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 a 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 StackOverflow!).

To quote a DBA 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."

HTH someone...

Peace...

Robb Sadler