SQL Server 数据类型的 C# 等效项 [英] C# Equivalent of SQL Server DataTypes

查看:34
本文介绍了SQL Server 数据类型的 C# 等效项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

For the following SQL Server datatypes, what would be the corresponding datatype in 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)

推荐答案

This is for SQL Server 2005.SQL Server 2008 的表有更新版本, SQL Server 2008 R2SQL Server 2012SQL Server 2014.

This is for SQL Server 2005. There are updated versions of the table for SQL Server 2008, SQL Server 2008 R2, SQL Server 2012 and SQL Server 2014.

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

The following table lists Microsoft SQL Server data types, their equivalents in the common language runtime (CLR) for SQL Server in the System.Data.SqlTypes namespace, and their native CLR equivalents in the Microsoft .NET Framework.

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

这篇关于SQL Server 数据类型的 C# 等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆