Converting a String to an Enumerated Value

You can convert a string to an enumerated value by using Enum.Parse(). For example, the following code converts the string "Int32" to the corresponding System.Data.DbType enum value:

Param.DbType = (DbType)Enum.Parse(typeof(DbType), "Int32", true);

This is a nice tip that will save you from writing some ugly code!

Leave a Reply

Your email address will not be published. Required fields are marked *