Equivalente en C # de los tipos de datos de SQL Server


Para los siguientes tipos de datos de SQL Server, ¿cuál sería el tipo de datos correspondiente en C#?

Números exactos

bigint
numeric
bit
smallint
decimal
smallmoney
int
tinyint
money

Números aproximados

float
real

Fecha y Hora

date
datetimeoffset
datetime2
smalldatetime
datetime
time

Cadenas de caracteres

char
varchar
text

Cadenas de caracteres Unicode

nchar
nvarchar
ntext

Cadenas Binarias

binary
varbinary
image

Otros Tipos De Datos

cursor
timestamp
hierarchyid
uniqueidentifier
sql_variant
xml
table

(fuente: MSDN )

Author: George Stocker, 2009-01-08

2 answers

Esto es para SQL Server 2005. Hay versiones actualizadas de la tabla para SQL Server 2008, SQL Server 2008 R2, SQL Server 2012 y SQL Server 2014.

Tipos de Datos de SQL Server y Sus Equivalentes de. NET Framework

La siguiente tabla muestra los tipos de datos de Microsoft SQL Server, sus equivalentes en common language runtime (CLR) para SQL Server en el sistema .Datos.SqlTypes espacio de nombres, y su CLR nativo equivalentes en 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
 848
Author: Örjan Jämte,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-06-05 17:37:11

SQL Server y.NET Framework se basan en diferentes tipos de sistemas. Por ejemplo, la estructura decimal de.NET Framework tiene una escala máxima de 28, mientras que los tipos de datos decimales y numéricos de SQL Server tienen una escala máxima de 38. Haga clic aquí es un enlace ! para más detalles

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

 5
Author: Salman,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-03-15 07:54:06