SQL Server 数据类型映射

SQL Server 和 .NET Framework 基于不同的类型系统。 例如,.NET Framework Decimal 结构的最大小数位数为 28,而 SQL Server 的 decimal 和 numeric 数据类型的最大小数位数为 38。 为了在读取和写入数据时维护数据的完整性,SqlDataReader 将公开用于返回 System.Data.SqlTypes 的对象的 SQL Server 特定的类型化访问器方法以及用于返回 .NET Framework 类型的访问器方法。 SQL Server 类型和 .NET Framework 类型也可通过 DbType 和 SqlDbType 类中的枚举表示,当您指定 SqlParameter 数据类型时可以使用这些枚举。

下表显示推断的 .NET Framework 类型、DbType 和 SqlDbType 枚举以及 SqlDataReader 的访问器方法。

SQL Server 数据库引擎类型 .NET Framework 类型 SqlDbType 枚举 SqlDataReader SqlTypes 类型化访问器 DbType 枚举 SqlDataReader DbType 类型化访问器
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

日期1

(SQL Server 2008 及更高版本)

DateTime Date 1 GetSqlDateTime Date 1 GetDateTime
datetime DateTime DateTime GetSqlDateTime DateTime GetDateTime
datetime2

(SQL Server 2008 及更高版本)

DateTime DateTime2 DateTime2 GetDateTime
datetimeoffset

(SQL Server 2008 及更高版本)

DateTimeOffset DateTimeOffset DateTimeOffset GetDateTimeOffset
decimal Decimal Decimal GetSqlDecimal Decimal GetDecimal
FILESTREAM 特性 (varbinary(max)) Byte[] VarBinary GetSqlBytes Binary GetBytes
float Double Float GetSqlDouble Double GetDouble
图像 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

数值 Decimal Decimal GetSqlDecimal Decimal GetDecimal
nvarchar String

Char[]

NVarChar GetSqlString String GetString

GetChars

实数 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 GetSqlMoney Decimal GetDecimal
sql_variant 对象2 Variant GetSqlValue 2 Object GetValue 2
文本 String

Char[]

Text GetSqlString String GetString

GetChars

时间

(SQL Server 2008 及更高版本)

TimeSpan Time Time GetDateTime
时间戳 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 AnsiStringString GetString

GetChars

xml Xml Xml GetSqlXml Xml

1无法设置DbType属性SqlParameterSqlDbType.Date
2使用特定的类型化访问器,如果你知道的基础类型sql_variant

来源https://docs.microsoft.com/zh-cn/dotnet/framework/data/adonet/sql-server-data-type-mappings

SQL Server 数据类型映射(转载)的更多相关文章

  1. (转)SQL Server 数据类型映射

    SQL Server 数据类型映射 SQL Server 和 .NET Framework 基于不同的类型系统. 例如,.NET Framework Decimal 结构的最大小数位数为 28,而 S ...

  2. SQL Server 数据类型映射 (ADO.NET)

    SQL Server 数据类型映射 (ADO.NET) .NET Framework 3.5 更新:November 2007 SQL Server 和 .NET Framework 基于不同的类型系 ...

  3. SQL Server 数据类型映射

    SQL Server 和 .NET Framework 基于不同的类型系统. 例如,.NET Framework Decimal 结构的最大小数位数为 28,而 SQL Server 的 decima ...

  4. SQL Server数据类型

    转载:http://www.ezloo.com/2008/10/sql_server_data_type.html    数据类型是数据的一种属性,是数据所表示信息的类型.任何一种语言都有它自己所固有 ...

  5. SQL Server游标 C# DataTable.Select() 筛选数据 什么是SQL游标? SQL Server数据类型转换方法 LinQ是什么? SQL Server 分页方法汇总

    SQL Server游标   转载自:http://www.cnblogs.com/knowledgesea/p/3699851.html. 什么是游标 结果集,结果集就是select查询之后返回的所 ...

  6. 为更好地设计数据库,重新整理sql server数据类型

    我们在平常开发过程中,在设计数据的时候,经常碰到数据类型选择的问题,为了更快,更合适地选择正确的数据类型,所以在这里做个总结. 分类 sql server 数据类型 c# 数据类型 描述 应用场景 字 ...

  7. MySql和SQL Server数据类型 对比

    My Sql 数据类型 SQL Server 数据类型 Yes/No bit Smallint(字节型) tinyint Integer(长整型) int Real(单精度浮点型)    real F ...

  8. SQL Server数据类型与SDE库表sde_type对照表

    SDE_column_registry 表管理所有注册列. 警告:如果使用 SQL 界面更改列定义,SDE_column_registry 表中的记录将不会更新.这可能导致之后的任何数据导出失败. S ...

  9. SQL Server 数据类型 Decimal介绍

    为SQL Server 数据类型,属于浮点数类型.存储数据范围是: -1038~1038-1 的固定精度和小数位的数字.一个decimal类型的数据占用了2~17个字节.decimal数据类型在SQL ...

随机推荐

  1. boost-字符文本处理

    1.lexical_cast 一些常见的数值,字符互转函数: 整型int: itoa()._itoa_s atoi()._ttoi 无符号整型unsigned int: _ultoa_s()._ult ...

  2. drf1 rest & restful规范

    web服务交互 我们在浏览器中能看到的每个网站,都是一个web服务.那么我们在提供每个web服务的时候,都需要前后端交互,前后端交互就一定有一些实现方案,我们通常叫web服务交互方案. 目前主流的三种 ...

  3. STM32外设初始化步骤

    1.定义外设结构体: 2.开启外设时钟: 3.调用缺省值配置函数: 4.外设具体配置: 5.外设使能.

  4. hdu 4027 Can you answer these queries?[线段树]

    题目 题意: 输入一个 :n  .(1<=n<<100000) 输入n个数    (num<2^63) 输入一个m :代表m个操作    (1<=m<<100 ...

  5. Python 装饰器(笔记,非原创)

    定义:本质是函数,为其他函数添加附加功能原则:1.不能修改被装饰的函数的源代码         2.不能修改被装饰的函数的调用方式知识储备:       1.函数即“变量”       2.高阶函数  ...

  6. 4.BeanPostProcessor 后处理Bean

     Bean种类 普通bean:之前操作的都是普通bean.<bean id="" class="A"> ,spring直接创建A实例,并返回 Fac ...

  7. JMeter 教程汇总链接

    http://www.360doc.com/content/14/0318/23/16361380_361732630.shtml 可以作为入门系列教程. 尽管网页也给出了视频链接,但是我不建议看视频 ...

  8. 制作Visual Studio 2019 (VS 2019) 离线安装包

    与制作Visual Studio 2017的离线安装包(https://www.cnblogs.com/danzhang/p/6534341.html)类似,可以使用--layout的参数在安装前先下 ...

  9. 9.2 翻译系列:数据注解特性之---Column【EF 6 Code First系列】

    原文链接:http://www.entityframeworktutorial.net/code-first/column-dataannotations-attribute-in-code-firs ...

  10. npm全局目录修改

    转载:http://www.qdfuns.com/notes/30749/0f66fcf5e62eed010f744d0d4adaa870.html 我之前安装npm时全是默认安装,模块全部安装在C盘 ...