各种数据类型对比

 

Parameter 的类型是 .NET Framework 数据提供程序特定的。如果指定类型,则在向数据源传递 Parameter 的值之前,将该值转换为 .NET Framework 数据提供程序类型。也可以通过通用的方式指定 Parameter 的类型,方法是将 Parameter 对象的 DbType 属性设置为特定的 DbType

Parameter 对象的 .NET Framework 数据提供程序类型将从 Parameter 对象的 Value 的 .NET Framework 类型来推断,或从 Parameter 对象的 DbType 来推断。下表显示了根据作为 Parameter 值传递的对象或指定的 DbType 推断出的 Parameter 类型。

.NET Framework 类型 System.Data.DbType SqlDbType OleDbType OdbcType OracleType

bool

Boolean

Bit

Boolean

Bit

Byte

byte

Byte

TinyInt

UnsignedTinyInt

TinyInt

Byte

byte[]

Binary

VarBinary. 如果字节数组大于 VarBinary 的最大大小(8000 字节),此隐式转换将失败。对于大于 8000 字节的字节数组,请显式设置 SqlDbType。

VarBinary

Binary

Raw

char

不支持从 char 推断 SqlDbType。

Char

Char

Byte

DateTime

DateTime

DateTime

DBTimeStamp

DateTime

DateTime

Decimal

Decimal

Decimal

Decimal

Numeric

Number

double

Double

Float

Double

Double

Double

float

Single

Real

Single

Real

Float

Guid

Guid

UniqueIdentifier

Guid

UniqueIdentifier

Raw

Int16

Int16

SmallInt

SmallInt

SmallInt

Int16

Int32

Int32

Int

Int

Int

Int32

Int64

Int64

BitInt

BigInt

BigInt

Number

object

Object

Variant

Variant

不支持从 Object 推断 OdbcType。

Blob

string

String

NVarChar。如果字符串大于 NVarChar 的最大大小(4000 个字符),此隐式转换将失败。对于大于 4000 个字符的字符串,请显式设置 SqlDbType。

VarWChar

NVarChar

NVarChar

TimeSpan

Time

不支持从 TimeSpan 推断 SqlDbType。

DBTime

Time

DateTime

UInt16

UInt16

不支持从 UInt16 推断 SqlDbType。

UnsignedSmallInt

Int

UInt16

UInt32

UInt32

不支持从 UInt32 推断 SqlDbType。

UnsignedInt

BigInt

UInt32

UInt64

UInt64

不支持从 UInt64 推断 SqlDbType。

UnsignedBigInt

Numeric

Number

AnsiString

VarChar

VarChar

VarChar

VarChar

AnsiStringFixedLength

Char

Char

Char

Char

Currency

Money

Currency

不支持从 Currency 推断 OdbcType。

Number

Date

不支持从 Date 推断 SqlType。

DBDate

Date

DateTime

SByte

不支持从 SByte 推断 SqlType。

TinyInt

不支持从 SByte 推断 OdbcType。

SByte

StringFixedLength

NChar

WChar

NChar

NChar

Time

不支持从 Time 推断 SqlType。

DBTime

Time

DateTime

VarNumeric

不支持从 VarNumeric 推断 SqlDbType。

VarNumeric

不支持从 VarNumeric 推断 OdbcType。

Number

Note注意

随 .NET Framework 1.0 版提供的 .NET Framework 数据提供程序不验证 Decimal 参数值的精度和小数位数是否有效,这可能会导致截断的数据被插入数据源。如果您使用的是 .NET Framework 1.0 版,请在设置该参数值之前,验证 Decimal 值的精度和小数位数是否有效。在 .NET Framework 1.1 版及更高版本中,当用无效的精度设置 Decimal 参数值时会引发异常。但仍将截断超出 Decimal 参数小数位数的小数位数值。

Note注意

对于 .NET Framework 1.0 以及更高版本,可以对 System.Data.SqlClient 使用 System.Data.SqlTypes。有关更多信息,请参见使用 SqlTypes

posted @ 2008-08-20 10:55  chinaifne  阅读(1613)  评论(0编辑  收藏  举报