当前位置:  开发笔记 > 编程语言 > 正文

C#等效的SQL Server数据类型

如何解决《C#等效的SQLServer数据类型》经验,为你挑选了3个好方法。

对于以下SQL Server数据类型,C#中相应的数据类型是什么?

精确的数字

bigint
numeric
bit
smallint
decimal
smallmoney
int
tinyint
money

近似数字

float
real

日期和时间

date
datetimeoffset
datetime2
smalldatetime
datetime
time

字符串

char
varchar
text

Unicode字符串

nchar
nvarchar
ntext

二进制字符串

binary
varbinary
image

其他数据类型

cursor
timestamp
hierarchyid
uniqueidentifier
sql_variant
xml
table

(来源:MSDN)



1> Örjan Jämte..:

这适用于SQL Server 2005.SQL Server 2008,SQL Server 2008 R2,SQL Server 2012和SQL Server 2014的表的更新版本.

SQL Server数据类型及其.NET Framework等价物

下表列出了Microsoft SQL Server数据类型,它们在System.Data.SqlTypes命名空间中SQL Server的公共语言运行时(CLR)中的等效项,以及Microsoft .NET Framework中它们的本机CLR等效项.

SQL Server data type          CLR data type (SQL Server)    CLR data type (.NET Framework)  
varbinary                     SqlBytes, SqlBinary           Byte[]  
binary                        SqlBytes, SqlBinary           Byte[]  
varbinary(1), binary(1)       SqlBytes, SqlBinary           byte, Byte[] 
image                         None                          None

varchar                       None                          None
char                          None                          None
nvarchar(1), nchar(1)         SqlChars, SqlString           Char, String, Char[]     
nvarchar                      SqlChars, SqlString           String, Char[] 
nchar                         SqlChars, SqlString           String, Char[] 
text                          None                          None
ntext                         None                          None

uniqueidentifier              SqlGuid                       Guid 
rowversion                    None                          Byte[]  
bit                           SqlBoolean                    Boolean 
tinyint                       SqlByte                       Byte 
smallint                      SqlInt16                      Int16  
int                           SqlInt32                      Int32  
bigint                        SqlInt64                      Int64 

smallmoney                    SqlMoney                      Decimal  
money                         SqlMoney                      Decimal  
numeric                       SqlDecimal                    Decimal  
decimal                       SqlDecimal                    Decimal  
real                          SqlSingle                     Single  
float                         SqlDouble                     Double  

smalldatetime                 SqlDateTime                   DateTime  
datetime                      SqlDateTime                   DateTime 

sql_variant                   None                          Object  
User-defined type(UDT)        None                          user-defined type     
table                         None                          None 
cursor                        None                          None
timestamp                     None                          None 
xml                           SqlXml                        None


.NET中的int与此表中的Int32相同,因此它也是SQL Server中的int.
@yogeshpatel,“ short”(https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/keywords/short)等于此清单中的System.Int16。因此,在SQL Server中将为smallint。

2> 小智..:

SQL Server和.Net数据类型映射



3> 小智..:

SQL Server和.NET Framework基于不同类型的系统.例如,.NET Framework Decimal结构的最大比例为28,而SQL Server十进制和数字数据类型的最大比例为38.单击此处为链接!细节

https://msdn.microsoft.com/en-us/library/cc716729(v=vs.110).aspx


倾向于答案的不是我,但理想情况下你应该回答这个问题,而不是提供与之相关的链接.
推荐阅读
雯颜哥_135
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有