.NET Framework、SQL Server、SqlDbType、DbType类型映射关系对应表

.NET FrameworkSQL ServerSqlDbTypeSqlDataReader SqlTypes typed accessorDbTypeSqlDataReader DbType typed accessor
BooleanbitBitGetSqlBooleanBooleanGetBoolean
BytetinyintTinyIntGetSqlByteByteGetByte
Int16smallintSmallIntGetSqlInt16Int16GetInt16
Int32intIntGetSqlInt32Int32GetInt32
Int64bigintBigIntGetSqlInt64Int64GetInt64
DecimalsmallmoneySmallMoneyGetSqlMoneyDecimalGetDecimal
DecimalmoneyMoneyGetSqlMoneyDecimalGetDecimal
DecimalnumericDecimalGetSqlDecimalDecimalGetDecimal
DecimaldecimalDecimalGetSqlDecimalDecimalGetDecimal
SinglerealRealGetSqlSingleSingleGetFloat
DoublefloatFloatGetSqlDoubleDoubleGetDouble
DateTimedate 1Date 1GetSqlDateTimeDate 1GetDateTime
DateTimesmalldatetimeDateTimeGetSqlDateTimeDateTimeGetDateTime
DateTimedatetimeDateTimeGetSqlDateTimeDateTimeGetDateTime
DateTimedatetime2DateTime2NoneDateTime2GetDateTime
DateTimeOffsetdatetimeoffsetDateTimeOffsetnoneDateTimeOffsetGetDateTimeOffset
TimeSpantimeTimenoneTimeGetDateTime
Byte[]binaryVarBinaryGetSqlBinaryBinaryGetBytes
Byte[]varbinaryVarBinaryGetSqlBinaryBinaryGetBytes
Byte[]imageBinaryGetSqlBinaryBinaryGetBytes
Byte[]timestampTimestampGetSqlBinaryBinaryGetBytes
Byte[]rowversionTimestampGetSqlBinaryBinaryGetBytes
Byte[]FILESTREAM attribute (varbinary(max))VarBinaryGetSqlBytesBinaryGetBytes
String

Char[]
charCharGetSqlStringAnsiStringFixedLength,

String
GetString

GetChars
String

Char[]
varcharVarCharGetSqlStringAnsiStringStringGetString

GetChars
String

Char[]
ncharNCharGetSqlStringStringFixedLengthGetString

GetChars
String

Char[]
nvarcharNVarCharGetSqlStringStringGetString

GetChars
String

Char[]
textTextGetSqlStringStringGetString

GetChars
String

Char[]
ntextNTextGetSqlStringStringGetString

GetChars
Object 2sql_variantVariantGetSqlValue 2ObjectGetValue 2
GuiduniqueidentifierUniqueIdentifierGetSqlGuidGuidGetGuid
XmlxmlXmlGetSqlXmlXmlnone

1 无法将 SqlParameter 的 DbType 属性设置为 SqlDbType.Date
2 如果已知 sql_variant 的基础类型,则使用特定的类型化访问器。

原创文章,作者:huoxiaoqiang,如若转载,请注明出处:https://www.huoxiaoqiang.com/experience/csexp/8469.html

发表评论

登录后才能评论