December 9, 2009

CLR Datatype Mapping tables

SQL CLR Data type mapping
SQL Server data typeCLR data type (SQL Server)CLR data type (.NET Framework)
bigintSqlInt64Int64, Nullable<Int64>
binarySqlBytes, SqlBinaryByte[]
bitSqlBooleanBoolean, Nullable<Boolean>
charNoneNone
cursorNoneNone
dateSqlDateTimeDateTime, Nullable<DateTime>
datetimeSqlDateTimeDateTime, Nullable<DateTime>
datetime2SqlDateTimeDateTime, Nullable<DateTime>
DATETIMEOFFSETNoneDateTimeOffset, Nullable<DateTimeOffset>
decimalSqlDecimalDecimal, Nullable<Decimal>
floatSqlDoubleDouble, Nullable<Double>
geographySqlGeography
defined in Microsoft.SqlServer.Types.dll Download here:feature pack.
None
geometrySqlGeometry
defined in Microsoft.SqlServer.Types.dll Download here: feature pack.
None
hierarchyidSqlHierarchyId
defined in Microsoft.SqlServer.Types.dll Download here: feature pack.
None
imageNoneNone
intSqlInt32Int32, Nullable<Int32>
moneySqlMoneyDecimal, Nullable<Decimal>
ncharSqlChars, SqlStringString, Char[]
ntextNoneNone
numericSqlDecimalDecimal, Nullable<Decimal>
nvarcharSqlChars, SqlString
SQLChars is a better match for
data transfer and access, and
SQLString is a better match for
performing String operations.
String, Char[]
nvarchar(1), nchar(1)SqlChars, SqlStringChar, String, Char[], Nullable<char>
realSqlSingleSingle, Nullable<Single>
rowversionNoneByte[]
smallintSqlInt16Int16, Nullable<Int16>
smallmoneySqlMoneyDecimal, Nullable<Decimal>
sql_variantNoneObject
tableNoneNone
textNoneNone
timeTimeSpanTimeSpan, Nullable<TimeSpan>
timestampNoneNone
tinyintSqlByteByte, Nullable<Byte>
uniqueidentifierSqlGuidGuid, Nullable<Guid>
User-defined type(UDT)NoneThe same class that is bound
to the user-defined type in
the same assembly or a
dependent assembly.
varbinary SqlBytes, SqlBinaryByte[]
varbinary(1), binary(1)SqlBytes, SqlBinarybyte, Byte[], Nullable<byte>
varcharNoneNone
xmlSqlXmlNone
Source: http://msdn.microsoft.com/en-us/library/ms131092.aspx




Image Source: http://msdn.microsoft.com/en-us/library/bb386947.aspx



Platform Invoke Data Types
Unmanaged type in Wtypes.h Unmanaged C language typeManaged class nameDescription
HANDLEvoid*System.IntPtr32 bits
BYTEunsigned charSystem.Byte8 bits
SHORTshortSystem.Int1616 bits
WORDunsigned shortSystem.UInt1616 bits
INTintSystem.Int3232 bits
UINTunsigned intSystem.UInt3232 bits
LONGlongSystem.Int3232 bits
BOOLlongSystem.Int3232 bits
DWORDunsigned longSystem.UInt3232 bits
ULONGunsigned longSystem.UInt3232 bits
CHARcharSystem.CharDecorate with ANSI.
LPSTRchar*System.String or System.StringBuilderDecorate with ANSI.
LPCSTRConst char*System.String or System.StringBuilderDecorate with ANSI.
LPWSTRwchar_t*System.String or System.StringBuilderDecorate with Unicode.
LPCWSTRConst wchar_t*System.String or System.StringBuilderDecorate with Unicode.
FLOATFloatSystem.Single32 bits
DOUBLEDoubleSystem.Double64 bits

Source: http://msdn.microsoft.com/en-us/library/aa720411(VS.71).aspx



Multiple Data Types Mapping Table
CategoryClass nameDescriptionVisual Basic data typeC# data typeManaged Extensions for C++ data typeJScript data type
IntegerByteAn 8-bit unsigned integer.BytebytecharByte
SByteAn 8-bit signed integer.Not CLS-compliant.SByte No built-in type.sbytesigned charSByte
Int16A 16-bit signed integer.Shortshortshortshort
Int32A 32-bit signed integer.Integerintint -or- longint
Int64A 64-bit signed integer.Longlong__int64long
UInt16A 16-bit unsigned integer.Not CLS-compliant.UInt16 No built-in type.ushortunsigned shortUInt16
UInt32A 32-bit unsigned integer.Not CLS-compliant.UInt32 No built-in type.uintunsigned int -or- unsigned longUInt32
UInt64A 64-bit unsigned integer.Not CLS-compliant.UInt64 No built-in type.ulongunsigned __int64UInt64
Floating pointSingleA single-precision (32-bit) floating-point number.Singlefloatfloatfloat
DoubleA double-precision (64-bit) floating-point number.Doubledoubledoubledouble
LogicalBooleanA Boolean value (true or false).Booleanboolboolbool
OtherCharA Unicode (16-bit) character.Charcharwchar_tchar
DecimalA 96-bit decimal value.DecimaldecimalDecimalDecimal
IntPtrA signed integer whose size
depends on the underlying platform
(a 32-bit value on a 32-bit platform
and a 64-bit value on a 64-bit platform).
IntPtr No built-in type.IntPtr No built-in type.IntPtr No built-in type.IntPtr
UIntPtrAn unsigned integer whose size
depends on the underlying platform
(a 32- bit value on a 32-bit platform
and a 64-bit value on a 64-bit platform).Not CLS-compliant.
UIntPtr No built-in type.UIntPtr No built-in type.UIntPtr No built-in type.UIntPtr
Class objectsObjectThe root of the object hierarchy.ObjectobjectObject*Object
StringAn immutable, fixed-length string of Unicode characters.StringstringString*String

Source: http://msdn.microsoft.com/en-us/library/aa720713(VS.71).aspx

No comments:

Post a Comment

Total Pageviews