SQL Server Data Type Mapping (ADO)

Source: Internet
Author: User
Tags sql server books

http://msdn.microsoft.com/zh-cn/library/cc716729 (vs.90). aspxSQL Server Data Type Mapping (ADO) . NET Framework 3.5Other versions3 out of 3 rated this helpful -rate this topic

Updated: November 2007

SQL Server and the. NET Framework are based on different types of systems. For example, the maximum size of the. NET Framework decimal structure is 28, while SQL Server's decimal and numeric data types have a maximum size of 38. To maintain data integrity while reading and writing data,SqlDataReader exposes SQL Server-specific typed accessor methods for returning System.Data.SqlTypes objects and for returning. NET Accessor methods for the Framework type. SQL Server types and. NET Framework types can also be represented by enumerations in the DbType and SqlDbType classes, which are available when you specify SqlParameter data types.

The following table shows the inferred. NET Framework types,DbType and SqlDbType enumerations, and accessor methods for SqlDataReader.

SQL Server Database Engine type

. NET Framework Types

SqlDbType Enumeration

SqlDataReader SqlTypes Typed accessors

DbType Enumeration

SqlDataReader DbType Typed accessors

bigint

Int64

BigInt

GetSqlInt64

Int64

GetInt64

Binary

Byte[]

VarBinary

GetSqlBinary

Binary

GetBytes

Bit

Boolean

Bit

Getsqlboolean

Boolean

Getboolean

Char

String

Char[]

Char

GetSqlString

Ansistringfixedlength,

String

GetString

GetChars

Date

(For SQL Server 2008 only)

Datetime

Date

GetSqlDateTime

Date

GetDateTime

Datetime

Datetime

Datetime

GetSqlDateTime

Datetime

GetDateTime

DateTime2

(For SQL Server 2008 only)

DateTime2

DateTime2

GetSqlDateTime

DateTime2

GetDateTime

DateTimeOffset

(For SQL Server 2008 only)

DateTimeOffset

DateTimeOffset

None

DateTimeOffset

Getdatetimeoffset

Decimal

Decimal

Decimal

GetSqlDecimal

Decimal

Getdecimal

FILESTREAM Property (varbinary (max)

Byte[]

VarBinary

GetSqlBytes

Binary

GetBytes

Float

Double

Float

GetSqlDouble

Double

GetDouble

Image

Byte[]

Binary

GetSqlBinary

Binary

GetBytes

Int

Int32

Int

GetSqlInt32

Int32

GetInt32

Money

Decimal

Money

Getsqlmoney

Decimal

Getdecimal

NChar

String

Char[]

NChar

GetSqlString

Stringfixedlength

GetString

GetChars

ntext

String

Char[]

NText

GetSqlString

String

GetString

GetChars

Numeric

Decimal

Decimal

GetSqlDecimal

Decimal

Getdecimal

nvarchar

String

Char[]

NVarChar

GetSqlString

String

GetString

GetChars

Real

Single

Real

Getsqlsingle

Single

GetFloat

RowVersion

Byte[]

Timestamp

GetSqlBinary

Binary

GetBytes

smalldatetime

Datetime

Datetime

GetSqlDateTime

Datetime

GetDateTime

smallint

Int16

SmallInt

GetSqlInt16

Int16

GetInt16

SmallMoney

Decimal

SmallMoney

GetSqlDecimal

Decimal

Getdecimal

sql_variant

object*

Variant

Getsqlvalue *

Object

GetValue *

Text

String

Char[]

Text

GetSqlString

String

GetString

GetChars

Time

(For SQL Server 2008 only)

TimeSpan

Time

None

Time

GetDateTime

Timestamp

Byte[]

Timestamp

GetSqlBinary

Binary

GetBytes

tinyint

Byte

TinyInt

GetSqlByte

Byte

GetByte

uniqueidentifier

Guid

uniqueidentifier

Getsqlguid

Guid

GetGuid

varbinary

Byte[]

VarBinary

GetSqlBinary

Binary

GetBytes

varchar

String

Char[]

VarChar

GetSqlString

Ansistring, String

GetString

GetChars

Xml

Xml

Xml

Getsqlxml

Xml

None

* If the underlying type of sql_variant is known, a specific typed accessor is used.

SQL Server Books Online reference

For more information about SQL Server data types, see SQL Server Books Online that corresponds to the version of SQL Server that you are using.

SQL Server 2000

SQL Server 2005

SQL Server 2008

Data type

Data type (Database engine)

Data type (Database engine)

Please seeConceptconfiguration parameters and parameter data Types (ADO)Other resourcesSQL Server data types and ADOSQL Server binary and large Value data (ADO)data type mappings in ADO

SQL Server Data Type Mapping (ADO)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.