how to map datatypes...

G

Guest

The MS SQL has a column using DEC(11) which is an unsignedInt.

What is the correct way to declare the unsignedInt variable in c# to insert
this value to MS SQL?

recall from SQL2k BOL
Use the int data type to store numbers in the range from -2,147,483,648
through 2,147,483,647 only (requires 4 bytes of storage per value).

What I like to do is use the entire range as a positive value.

Thanks.
 
C

Charles Calvert

The MS SQL has a column using DEC(11) which is an unsignedInt.

What is the correct way to declare the unsignedInt variable in c# to insert
this value to MS SQL?

2 bytes: UInt16
4 bytes: UInt32
8 bytes: UInt64

Note that these types are not CLS-compliant.
 
D

Dave Sexton

Hi,

In Sql Server, "dec" is an alias for the "decimal" data type. Dec(11)
represents a signed, numeric data type with a precision of 11 and no scale,
meaning that there can be no digits to the right side of the decimal.

According to the docs, a precision of 11 requires 9 bytes:

"decimal and numeric (Transact-SQL)"
http://msdn2.microsoft.com/en-us/library/ms187746.aspx

To maximize the capacity of values in managed code and to retain the sign of
the number, you must use System.Decimal, which is the only primitive structure
capable of representing all possible values of dec(11), AFAIK.
 
G

Guest

Thank you both of you.

Yes, Dave. I am going to try using system.decimal in c# to
represent/passing dec(11) in ms sql.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top