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. MFC字体样式和颜色设置

    在编写MFC界面程序时,可能会使用不同大小或者颜色的字体,这里稍做记录. 使用方法 CFont *m_pFont;//创建新的字体 m_pFont = new CFont; m_pFont->C ...

  2. clickhouse安装使用文档

    Clickhouse简介 Clickhouse是什么 1. 开源的列存储数据库管理系统 2. 支持线性扩展 3. 简单方便 4. 高可靠性 5. 容错(支持多主机异步复制,可以跨多个数据中心部署. 单 ...

  3. Python开发——6.文件操作

    一.文件操作 1.文件操作的处理流程 打开文件得到文件句柄并赋值给一个变量====>通过句柄对文件进行分析====>关闭文件 #1. 打开文件,得到文件句柄并赋值给一个变量 f=open( ...

  4. 找出数组中求和等于y的所有子数组

    算法记录: 给定一个数组x,每个元素都是正整数,找出其中满足条件"求和等于y"的所有子数组.(简化问题,每个元素都不相等) x=[x1,...,xn],暴力搜索,复杂度O(2^n) ...

  5. 背水一战 Windows 10 (66) - 控件(WebView): 监听和处理 WebView 的事件

    [源码下载] 背水一战 Windows 10 (66) - 控件(WebView): 监听和处理 WebView 的事件 作者:webabcd 介绍背水一战 Windows 10 之 控件(WebVi ...

  6. [转]kaldi上的深度神经网络

    转:http://blog.csdn.net/wbgxx333/article/details/41019453 深度神经网络已经是语音识别领域最热的话题了.从2010年开始,许多关于深度神经网络的文 ...

  7. 由百度 “PHP薪资” 引发的思考

    昨天晚上睡觉的时候百度了一下 “PHP薪资”,看到了各种各样的答案,从百度知道到知乎,再到各个论坛……答案也是从 2k-16k 不等(不过说实话,2k是吓到我了),其中一些答案说到了在中国从事某一行业 ...

  8. 关于 SQL 注入的问题

    拼串 (Statement)方式 1.编译次数多,效率比较低:会出现SQL注入问题(数据安全问题):先传参数再编译. 2.Sql文对应的字符串不一样,需要再次编译.Sql文对应的字符串一样,不会再编译 ...

  9. EXCEL在改动某几个单元格时隐藏空列

    概述 今天我哥来找我帮他搞下excel表格,本着程序猿对程序无所不能的精神,我爽快的答应了.结果查了半天才搞定.现在记录在此,供自己以后参考,相信对其他人也有用. PS:这几天正在弄博客,马上就要弄完 ...

  10. spring框架学习笔记3:使用注解代替配置文件

    1.导入context约束:spring-context-4.2.xsd 2.design模式打开xml配置文件,右键edit namespaces,点击add添加 完成后应该是这样: 配置文件中这样 ...