Nota
El acceso a esta página requiere autorización. Puede intentar iniciar sesión o cambiar directorios.
El acceso a esta página requiere autorización. Puede intentar cambiar los directorios.
SQL Server y .NET Framework se basan en sistemas de tipos distintos. Por ejemplo, la estructura Decimal de .NET Framework tiene una escala máxima de 28, mientras que los tipos de datos decimal y numérico de SQL Server tienen una escala máxima de 38. Para mantener la integridad de los datos cuando se leen y escriben, SqlDataReader expone métodos de descriptores de acceso con tipo específicos de SQL Server que devuelven objetos de System.Data.SqlTypes, así como métodos de descriptores de acceso que devuelven tipos de .NET Framework. Los tipos de SQL Server y los de .NET Framework se representan también mediante enumeraciones en las clases DbType y SqlDbType, que puede usar al especificar los tipos de datos SqlParameter.
En la tabla siguiente se muestra el tipo de .NET Framework deducido, las enumeraciones DbType y SqlDbType y los métodos de descriptor de acceso para SqlDataReader.
Tipo de motor de base de datos SQL Server | Tipo de .NET Framework | Enumeración SqlDbType | Descriptor de acceso con tipo SqlDataReader SqlTypes | Enumeración DbType | Descriptor de acceso con tipo SqlDataReader DbType |
---|---|---|---|---|---|
bigint | Int64 | BigInt | GetSqlInt64 | Int64 | GetInt64 |
binario | Byte[] | VarBinary | GetSqlBinary | Binary | GetBytes |
poco | Booleano | Bit | GetSqlBoolean | Boolean | GetBoolean |
carbonizar | Cuerda Char[] |
Char | GetSqlString |
AnsiStringFixedLength, String |
GetString GetChars |
fecha 1 (SQL Server 2008 y posteriores) |
Fecha y hora | Date 1 | GetSqlDateTime | Date 1 | GetDateTime |
fecha y hora | Fecha y hora | DateTime | GetSqlDateTime | DateTime | GetDateTime |
datetime2 (SQL Server 2008 y posteriores) |
Fecha y hora | DateTime2 | Ninguno | DateTime2 | GetDateTime |
datetimeoffset (SQL Server 2008 y posteriores) |
Desplazamiento de Fecha y Hora | DateTimeOffset | ninguno | DateTimeOffset | GetDateTimeOffset |
Decimal | Decimal | Decimal | GetSqlDecimal | Decimal | GetDecimal |
Atributo FILESTREAM (varbinary(max)) | Byte[] | VarBinary | GetSqlBytes | Binary | GetBytes |
FLOAT | Doble | Float | GetSqlDouble | Double | GetDouble |
imagen | Byte[] | Binary | GetSqlBinary | Binary | GetBytes |
Int | Int32 | Int | GetSqlInt32 | Int32 | GetInt32 |
dinero | Decimal | Money | GetSqlMoney | Decimal | GetDecimal |
NCHAR | Cuerda Char[] |
NChar | GetSqlString | StringFixedLength | GetString GetChars |
ntexto | Cuerda Char[] |
NText | GetSqlString | String | GetString GetChars |
NUMERIC | Decimal | Decimal | GetSqlDecimal | Decimal | GetDecimal |
NVARCHAR | Cuerda Char[] |
NVarChar | GetSqlString | String | GetString GetChars |
verdadero | Soltero | Real | GetSqlSingle | Single | GetFloat |
rowversion | Byte[] | Timestamp | GetSqlBinary | Binary | GetBytes |
smalldatetime | Fecha y hora | DateTime | GetSqlDateTime | DateTime | GetDateTime |
SMALLINT | Int16 | SmallInt | GetSqlInt16 | Int16 | GetInt16 |
SMALLMONEY | Decimal | SmallMoney | GetSqlMoney | Decimal | GetDecimal |
sql_variant | Objeto 2 | Variant | GetSqlValue 2 | Object | GetValue 2 |
texto | Cuerda Char[] |
Text | GetSqlString | String | GetString GetChars |
Tiempo (SQL Server 2008 y posteriores) |
TimeSpan | Time | ninguno | Time | GetTimeSpan |
marca de tiempo | Byte[] | Timestamp | GetSqlBinary | Binary | GetBytes |
TINYINT | byte | TinyInt | GetSqlByte | Byte | GetByte |
UNIQUEIDENTIFIER | GUID | UniqueIdentifier | GetSqlGuid | Guid | GetGuid |
varbinary | Byte[] | VarBinary | GetSqlBinary | Binary | GetBytes |
varchar | Cuerda Char[] |
VarChar | GetSqlString | AnsiString, String | GetString GetChars |
Xml | XML | Xml | GetSqlXml | Xml | ninguno |
1 No puede establecer la propiedad DbType
de SqlParameter
en SqlDbType.Date
.
2 Utilice un descriptor de acceso con tipo si conoce el tipo subyacente de sql_variant
.
SQL Server, documentación
Para obtener información sobre los tipos de datos de SQL Server, vea Tipos de datos (Transact-SQL).