DBNull is a special type: it represents an "empty value" in database nullable column. When you issue a SELECT request against the database any matching rows that contain an SQL NULL value is returned as an instance of the
DBNull Class[
^]
Although it represents a NULL value in the DB, it isn't the same as a null value in your coding language - you can't directly cast it to any other type.
I'd suggest writing a generic conversion method similar to this:
public static T ConvertDBValue<T>(object o)
{
if (o == null || o == DBNull.Value)
{
return default(T);
}
else
{
return (T)o;
}
}
And call that for each DB value you process.