Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
System.Data.SqlTypes Namespace

The System.Data.SqlTypes namespace provides classes for native data types in SQL Server. These classes provide a safer, faster alternative to the data types provided by the .NET Framework common language runtime (CLR). Using the classes in this namespace helps prevent type conversion errors caused by loss of precision. Because other data types are converted to and from SqlTypes behind the scenes, explicitly creating and using objects within this namespace also yields faster code.

Each data type in SqlTypes has its equivalent data type in SQL Server, with the same underlying data representation. Many of them also have equivalent data types in the CLR. However, SqlDateTime, SqlDecimal, and SqlString have different underlying data structures with their corresponding .NET Framework data types.

The following table maps the members of the SqlTypes namespace to Microsoft SQL Server data types and to the members of the SqlDbType enumeration. For a complete listing of SQL Server data types, inferred .NET Framework types, enumerations and accessory methods, see SQL Server Data Type Mappings (ADO.NET).

.NET Framework SqlTypes

Native SQL Server

.NET Framework SqlDbType

SqlBinary

binary, image, timestamp, varbinary

Binary, Image, TimeStamp, VarBinary

SqlBoolean

bit

Bit

SqlByte

tinyint

TinyInt

SqlDateTime

datetime, smalldatetime

DateTime, SmallDateTime

SqlDecimal

numeric, decimal

Decimal

SqlDouble

float

Float

SqlFileStream

varbinary

VarBinary

SqlGuid

uniqueidentifier

UniqueIdentifier

SqlInt16

smallint

SmallInt

SqlInt32

int

Int

SqlInt64

bigint

BigInt

SqlMoney

money, smallmoney

Money, SmallMoney

SqlSingle

real

Real

SqlString

char, nchar, text, ntext, nvarchar, varchar

Char, NChar, Text, Ntext, NVarChar, VarChar

SqlXml

xml

Xml

  ClassDescription
Public classSqlAlreadyFilledException The SqlAlreadyFilledException class is not intended for use as a stand-alone component, but as a class from which other classes derive standard functionality.
Public classSqlBytes Represents a mutable reference type that wraps either a Buffer or a Stream.
Public classSqlChars SqlChars is a mutable reference type that wraps a Char array or a SqlString instance.
Public classSqlFileStreamExposes SQL Server data that is stored with the FILESTREAM column attribute as a sequence of bytes.
Public classSqlNotFilledException The SqlNotFilledException class is not intended for use as a stand-alone component, but as a class from which other classes derive standard functionality.
Public classSqlNullValueException The exception that is thrown when the Value property of a System.Data.SqlTypes structure is set to null.
Public classSqlTruncateException The exception that is thrown when you set a value into a System.Data.SqlTypes structure would truncate that value.
Public classSqlTypeException The base exception class for the System.Data.SqlTypes.
Public classSqlTypesSchemaImporterExtensionHelper The SqlTypesSchemaImporterExtensionHelper class is not intended for use as a stand-alone component, but as a class from which other classes derive standard functionality.
Public classSqlXml Represents XML data stored in or retrieved from a server.
Public classTypeBigIntSchemaImporterExtension The TypeBigIntSchemaImporterExtension class is not intended for use as a stand-alone component, but as a class from which other classes derive standard functionality.
Public classTypeBinarySchemaImporterExtension The TypeBinarySchemaImporterExtension class is not intended for use as a stand-alone component, but as a class from which other classes derive standard functionality.
Public classTypeBitSchemaImporterExtension The TypeBitSchemaImporterExtension class is not intended for use as a stand-alone component, but as a class from which other classes derive standard functionality.
Public classTypeCharSchemaImporterExtension The TypeCharSchemaImporterExtension class is not intended for use as a stand-alone component, but as a class from which other classes derive standard functionality.
Public classTypeDateTimeSchemaImporterExtension The TypeDateTimeSchemaImporterExtension class is not intended for use as a stand-alone component, but as a class from which other classes derive standard functionality.
Public classTypeDecimalSchemaImporterExtension The TypeDecimalSchemaImporterExtension class is not intended for use as a stand-alone component, but as a class from which other classes derive standard functionality.
Public classTypeFloatSchemaImporterExtension The TypeFloatSchemaImporterExtension class is not intended for use as a stand-alone component, but as a class from which other classes derive standard functionality.
Public classTypeIntSchemaImporterExtension The TypeIntSchemaImporterExtension class is not intended for use as a stand-alone component, but as a class from which other classes derive standard functionality.
Public classTypeMoneySchemaImporterExtension The TypeMoneySchemaImporterExtension class is not intended for use as a stand-alone component, but as a class from which other classes derive standard functionality.
Public classTypeNCharSchemaImporterExtension The TypeNCharSchemaImporterExtension class is not intended for use as a stand-alone component, but as a class from which other classes derive standard functionality.
Public classTypeNTextSchemaImporterExtension The TypeNTextSchemaImporterExtension class is not intended for use as a stand-alone component, but as a class from which other classes derive standard functionality.
Public classTypeNumericSchemaImporterExtension The TypeNumericSchemaImporterExtension class is not intended for use as a stand-alone component, but as a class from which other classes derive standard functionality.
Public classTypeNVarCharSchemaImporterExtension The TypeNVarCharSchemaImporterExtension class is not intended for use as a stand-alone component, but as a class from which other classes derive standard functionality.
Public classTypeRealSchemaImporterExtension The TypeRealSchemaImporterExtension class is not intended for use as a stand-alone component, but as a class from which other classes derive standard functionality.
Public classTypeSmallDateTimeSchemaImporterExtension The TypeSmallDateTimeSchemaImporterExtension class is not intended for use as a stand-alone component, but as a class from which other classes derive standard functionality.
Public classTypeSmallIntSchemaImporterExtension The TypeSmallIntSchemaImporterExtension class is not intended for use as a stand-alone component, but as a class from which other classes derive standard functionality.
Public classTypeSmallMoneySchemaImporterExtension The TypeSmallMoneySchemaImporterExtension class is not intended for use as a stand-alone component, but as a class from which other classes derive standard functionality.
Public classTypeTextSchemaImporterExtension The TypeTextSchemaImporterExtension class is not intended for use as a stand-alone component, but as a class from which other classes derive standard functionality.
Public classTypeTinyIntSchemaImporterExtension The TypeTinyIntSchemaImporterExtension class is not intended for use as a stand-alone component, but as a class from which other classes derive standard functionality.
Public classTypeUniqueIdentifierSchemaImporterExtension The TypeUniqueIdentifierSchemaImporterExtension class is not intended for use as a stand-alone component, but as a class from which other classes derive standard functionality.
Public classTypeVarBinarySchemaImporterExtension The TypeVarBinarySchemaImporterExtension class is not intended for use as a stand-alone component, but as a class from which other classes derive standard functionality.
Public classTypeVarCharSchemaImporterExtension The TypeVarCharSchemaImporterExtension class is not intended for use as a stand-alone component, but as a class from which other classes derive standard functionality.
Public classTypeVarImageSchemaImporterExtension The TypeVarImageSchemaImporterExtension class is not intended for use as a stand-alone component, but as a class from which other classes derive standard functionality.
  StructureDescription
Public structureSqlBinaryRepresents a variable-length stream of binary data to be stored in or retrieved from a database.
Public structureSqlBooleanRepresents an integer value that is either 1 or 0 to be stored in or retrieved from a database.
Public structureSqlByteRepresents an 8-bit unsigned integer, in the range of 0 through 255, to be stored in or retrieved from a database.
Public structureSqlDateTimeRepresents the date and time data ranging in value from January 1, 1753 to December 31, 9999 to an accuracy of 3.33 milliseconds to be stored in or retrieved from a database. The SqlDateTime structure has a different underlying data structure from its corresponding .NET Framework type, DateTime, which can represent any time between 12:00:00 AM 1/1/0001 and 11:59:59 PM 12/31/9999, to the accuracy of 100 nanoseconds. SqlDateTime actually stores the relative difference to 00:00:00 AM 1/1/1900. Therefore, a conversion from "00:00:00 AM 1/1/1900" to an integer will return 0.
Public structureSqlDecimalRepresents a numeric value between - 10^38 +1 and 10^38 - 1, with fixed precision and scale.
Public structureSqlDoubleRepresents a floating-point number within the range of -1.79E +308 through 1.79E +308 to be stored in or retrieved from a database.
Public structureSqlGuidRepresents a GUID to be stored in or retrieved from a database.
Public structureSqlInt16Represents a 16-bit signed integer to be stored in or retrieved from a database.
Public structureSqlInt32Represents a 32-bit signed integer to be stored in or retrieved from a database.
Public structureSqlInt64Represents a 64-bit signed integer to be stored in or retrieved from a database.
Public structureSqlMoneyRepresents a currency value ranging from -2 63 (or -922,337,203,685,477.5808) to 2 63 -1 (or +922,337,203,685,477.5807) with an accuracy to a ten-thousandth of currency unit to be stored in or retrieved from a database.
Public structureSqlSingleRepresents a floating point number within the range of -3.40E +38 through 3.40E +38 to be stored in or retrieved from a database.
Public structureSqlStringRepresents a variable-length stream of characters to be stored in or retrieved from the database. SqlString has a different underlying data structure from its corresponding .NET Framework String data type.
  InterfaceDescription
Public interfaceINullable All the System.Data.SqlTypes objects and structures implement the INullable interface.
  EnumerationDescription
Public enumerationSqlCompareOptions Specifies the compare option values for a SqlString structure.
Public enumerationStorageState The StorageState enumeration is not intended for use as a stand-alone component, but as an enumeration from which other classes derive standard functionality.
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Still no SmallDateTime Min/Max Values?      mcgmatt   |   Edit   |   Show History

In the table of types above, it groups datetime & smalldatetime together under SqlDateTime, presumably because you can use a .NET DateTime when working with smalldatetime values. But the problem is that you can't always write a DateTime value to a smalldatetime column. If you try to write SqlDateTime.MinValue or SqlDateTime.MaxValue to a smalldatetime, it throws an exception. So the solution is to check the date and fix the value before writing it. But since .NET doesn't provide the min/max values for smalldatetime, programmers have to look them up and hard-code the values in their comparison. If smalldatetime was a deprecated type in SQL Server that was just around for legacy use, I would understand. But it's a valid SQL type, so .NET should support it. If you don't want to create a SqlSmallDateTime type (after six years, it's pretty clear that you don't), how about at least throwing us a bone and adding SqlDateTime.SmallMinValue and SqlDateTime.SmallMaxValue?

Aye!      mxm0q1n   |   Edit   |   Show History
I vote in favor of that most excellent notion. If there is to be no SqlSmallDateTime, then at least a SqlDateTime.SmallMinValue and SmallMaxValue would move us away from hard coding a constant for an otherwise random looking date like "6/6/2079" every time we write a DAL for SQL Server. Good call.
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker