Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can T-SQL store ulong's?

I want to store a C#.NET ulong into a T-SQL database. I don't see any provisions for doing this, as the SQL bigint has the same Min/Max values as a normal long.

Is there any way I can do this? Or is catching an OverflowException my only hope?

like image 277
Onion-Knight Avatar asked Jun 02 '10 14:06

Onion-Knight


1 Answers

This should answer your question:

http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/ff08c190-a981-4896-9542-3f64b95a84a2/

You would use BigInt, you just have to be careful in how you convert the signed type back into an unsigned type in C#

// This has not been tested
unchecked
{
    myUlong = myDataReader.GetInt64(...);
}

...

The other possibility is to use VarBinary with a length of 8, then convert the bytes to a ulong in C#

like image 113
Neil N Avatar answered Sep 22 '22 08:09

Neil N