views:

8146

answers:

2

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

(source: MSDN)

+11  A: 

I think this is what you might be looking for:

http://msdn.microsoft.com/en-us/library/ms131092.aspx

Andrew Hare
Could you post that here? I can see the link, but I know that links may die, so having that information on this site would be a boon. I'm voting you up anyway. :-)
George Stocker
MSDN is pretty reliable, as links go. It's not like linking into a random blog or forum somewhere.
Joel Coehoorn
I found this by googling "c# sql data types". I think having the link here is even a bit of overkill as this kind of information is not difficult to find.
Andrew Hare
@Joel Coehoorn: Really? I can't count the number of times I've clicked an MSDN link and got the "That has moved, and we don't know where" message. Maybe it's better now than historically, but I *know* I've seen that page more than once!
Harper Shelby
@Harper Shelby: I second that! Microsoft is **terrible** about restructuring their URIs and invalidating old links. So much so that I sometimes hesitate before posting MSDN links here on SO, worried that someone who stumbles upon the post a few years from now may be left high and dry.
P Daddy
... or even a few months from now, I might add.
P Daddy
@Harper Shelby: That was the impetus for my question. MSDN is nothing if not shaky.
George Stocker
+17  A: 

It could help to get this answer searchable to have it all in the post as George Stocker wanted.

This is for SQL Server 2005. There is an updated version of the table for SQL Server 2008.

SQL Server Data Types and Their .NET Framework Equivalents

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
Örjan Jämte