SQL Server Data Type Mappings (ADO.NET)
SQL Server and the .NET Framework are based on different type systems. For example, the .NET Framework Decimal structure has a maximum scale of 28, whereas the SQL Server decimal and numeric data types have a maximum scale of 38. To maintain data integrity when reading and writing data, the SqlDataReader exposes SQL Server–specific typed accessor methods that return objects of System.Data.SqlTypes as well as accessor methods that return .NET Framework types. Both SQL Server types and .NET Framework types are also represented by enumerations in the DbType and SqlDbType classes, which you can use when specifying SqlParameter data types.
The following table shows the inferred .NET Framework type, the DbType and SqlDbType enumerations, and the accessor methods for the SqlDataReader.
SQL Server Database Engine type |
.NET Framework type |
SqlDbType enumeration |
SqlDataReader SqlTypes typed accessor |
DbType enumeration |
SqlDataReader DbType typed accessor |
---|---|---|---|---|---|
bigint |
Int64 |
||||
binary |
Byte[] |
||||
bit |
Boolean |
||||
char |
String Char[] |
||||
date (SQL Server 2008 only) |
DateTime |
||||
datetime |
DateTime |
||||
datetime (SQL Server 2008 only) |
DateTime |
None |
|||
datetimeoffset (SQL Server 2008 only) |
DateTimeOffset |
none |
|||
decimal |
Decimal |
||||
FILESTREAM attribute (varbinary(max) |
Byte[] |
||||
float |
Double |
||||
image |
Byte[] |
||||
int |
Int32 |
||||
money |
Decimal |
||||
nchar |
String Char[] |
||||
ntext |
String Char[] |
||||
numeric |
Decimal |
||||
nvarchar |
String Char[] |
||||
real |
Single |
||||
rowversion |
Byte[] |
||||
smalldatetime |
DateTime |
||||
smallint |
Int16 |
||||
smallmoney |
Decimal |
||||
sql_variant |
Object * |
GetValue * |
|||
text |
String Char[] |
||||
time (SQL Server 2008 only) |
TimeSpan |
none |
|||
timestamp |
Byte[] |
||||
tinyint |
Byte |
||||
uniqueidentifier |
Guid |
||||
varbinary |
Byte[] |
||||
varchar |
String Char[] |
||||
xml |
Xml |
none |
* Use a specific typed accessor if you know the underlying type of the sql_variant.
SQL Server Books Online Reference
For more information about SQL Server data types, see the version of SQL Server Books Online for the version of SQL Server you are using.
SQL Server 2000 |
SQL Server 2005 |
SQL Server 2008 |
---|---|---|
See Also
Concepts
Configuring Parameters and Parameter Data Types (ADO.NET)
Other Resources
SQL Server Data Types and ADO.NET