首页 文章

C#等效的SQL Server数据类型

提问于
浏览
468

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

Exact Numerics

bigint
numeric
bit
smallint
decimal
smallmoney
int
tinyint
money

Approximate Numerics

float
real

Date and Time

date
datetimeoffset
datetime2
smalldatetime
datetime
time

Character Strings

char
varchar
text

Unicode Character Strings

nchar
nvarchar
ntext

Binary Strings

binary
varbinary
image

Other Data Types

cursor
timestamp
hierarchyid
uniqueidentifier
sql_variant
xml
table

(来源:MSDN

2 回答

  • 878

    这是SQL Server 2005 . 该表的更新版本为SQL Server 2008SQL Server 2008 R2SQL Server 2012SQL 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
    
  • 5

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

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

相关问题