Section 4.9. SQL Server Data Types in the .NET Framework


4.9. SQL Server Data Types in the .NET Framework

The System.Data.SqlTypes namespace is part of the base class library of the .NET Framework. The namespace provides data types that map closely to native SQL Server data types. There are differences between SqlTypes data types and .NET Framework data types:

  • SqlTypes data types support NULL values while .NET Framework data types do not. All arithmetic and bitwise operators and most functions return NULL if any SqlTypes operands or arguments are NULL.

  • SqlTypes provides a SqlBoolean data type that represents a tristate logical valueTRue, false, and null (unknown value).

  • The .NET Framework Decimal data type and the corresponding SQL Server Decimal data type have different maximum values. The Decimal data type assumes maximum precision, whereas the SqlDecimal data type and the SQL Server Decimal data type have the same maximum precision, scale, and semantics.

  • Exceptions are thrown for all overflow and underflow errors and divide-by-zero errors when using SqlTypes data types. This behavior is not guaranteed with .NET Framework data types.

Table 4-16 lists SQL Server data types and their equivalents in the System.Data.SqlTypes namespace and in the .NET Framework.

Table 4-16. SQL Server, System.Data.SqlTypes, and .NET Framework data type equivalents

SQL Server data type

System.Data.SqlTypes data type

.NET Framework data type

varbinary

SqlBytes, SqlBinary

Byte[]

binary

SqlBytes, SqlBinary

Byte[]

image

None

None

varchar

None

None

char

None

None

nvarchar

SqlChars, SqlString

String, Char[]

nchar

SqlChars, SqlString

String, Char[]

text

None

None

ntext

None

None

uniqueidentifier

SqlGuid

Guid

rowversion

None

Byte[]

bit

SqlBoolean

Boolean

tinyint

SqlByte

Byte

smallint

SqlInt16

Int16

int

SqlInt32

Int32

bigint

SqlInt64

Int64

smallmoney

SqlMoney

Decimal

money

SqlMoney

Decimal

numeric

SqlDecimal

Decimal

decimal

SqlDecimal

Decimal

real

SqlSingle

Single

float

SqlDouble

Double

smalldatetime

SqlDateTime

DateTime

datetime

SqlDateTime

DateTime

sql_variant

None

Object

User-defined type (UDT)

None

Same class bound to the type in the registered assembly or dependent assembly

table

None

None

cursor

None

None

timestamp

None

None

xml

SqlXml

None




Programming SQL Server 2005
Programming SQL Server 2005
ISBN: 0596004796
EAN: 2147483647
Year: 2007
Pages: 147
Authors: Bill Hamilton

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net