Mapping Sql Types to .NET Types

by justin 12. September 2007 01:32
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.
 
Here is the sql type mapper I created 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

Tags: , , , , , , , , , , , , , ,

NBusiness | SQL | .NET | NBusiness | SQL | .NET | NBusiness | SQL | .NET | NBusiness | SQL | .NET | NBusiness | SQL | .NET

Comments are closed

About Me

sweetest hat ever

I'm a software developer from Minnesota and this blog largely focuses on various technical concepts I am thinking about at the moment. I currently work for Microsoft in the St. Paul office of the Expression product group.

RecentPosts