tags:

views:

1981

answers:

2

How do I best convert a System.Data.DbType enumeration value to the corresponding (or at least one of the possible corresponding) System.Type values?

For example:

DbType.StringFixedLength -> System.String 
DbType.String -> System.String
DbType.Int32 -> System.Int32

I've only seen very "dirty" solutions but nothing really clean.

(yes, it's a follow up to a different question of mine, but it made more sense as two seperate questions)

+2  A: 

AFAIK there is no built-in converter in .NET for converting a SqlDbType to a System.Type. But knowing the mapping you can easily roll your own converter ranging from a simple dictionary to more advanced (XML based for extensability) solutions.

The mapping can be found here: http://www.carlprothman.net/Default.aspx?tabid=97

A example of a converter can be found here: http://www.koders.com/csharp/fid81BF77665BE889E51EB9B3861C9BFBDE4A1A7AC5.aspx

smink
+1  A: 

I'm not sure what you classify as "dirty" but here is a link to a quite neatly defined Converter class for T-SQL (SQL Server)

http://www.koders.com/csharp/fid81BF77665BE889E51EB9B3861C9BFBDE4A1A7AC5.aspx

Ollie