Mapping Sql Types to .NET Types

I bet there is an article out there somewhere that tells you exactly what .NET Types to use with the corresponding SQL column types but I couldn’t find it anywhere. After scanning for a few minutes I decided to just write something up that tells me definitively what Type to use.
In this case I needed it because I had a bug in NBusiness whith the mapping to the double. After changing the Type a few times I couldn’t figure out what Type to actually map to a double. So I created a table that has one column of each type and I used a simple SqlDataReader to figure out the .NET Type of the field.
I created a simple type mapper just to show me what I wanted. And here are the results:
Sql Type .NET Type
bigint long
binary byte[]
bit bool
char string
datetime DateTime
decimal decimal
float double
int int
money decimal
nchar string
ntext string
nvarchar string
real single
smalldatetime DateTime
smallint short
smallmoney decimal
sql_variant object
text string
tinestamp byte[]
tinyint byte
uniqueidentifier Guid
varbinary byte[]
xml string

Author: justinmchase

I'm a Software Developer from Minnesota.

%d bloggers like this: