Casting an Object as an SqlDbType enumeration (possible)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Thanks to anyone in advance who can help :)

Ok, I know this is a far stretch, but what I'm trying to do is to cast a
System.object as one of the SqlDbType enumerations (SqlDbType.Int,
-.NVarchar, etc.) Is this anyway possible? Through inheritance, or anything?
 
First, you can't cast to SqlDbType.Int or SqlDbType.NVarchar. SqlDbType is
an enumeration. Thus, SqlDbType.Int is a value, not a type.

If I understand what you're trying to do, I think you have an object
(presumably of a known type) that you would like to convert into the
equivalent type in the System.Data.SqlTypes namespace. This can be done
since all of the types in the System.Data.SqlTypes namespace have
constructors that have parameters that take the appropriate type in the
System namespace. For example, SqlInt32 takes an Int32 object as a
parameter. Note that these types do not correspond exactly with the
SqlDbType enumeration. For example when SqlDbType.NVarChar and
SqlDbType.VarChar are used, the appropriate type to use from the
System.Data.SqlTypes namespace is SqlString.

Hope this helps.
 
Back
Top