static private SqlDbTypeToValueType ( SqlDbType sqlDbType ) : |
||
sqlDbType | SqlDbType | |
return |
internal static Type SqlDbTypeToValueType(SqlDbType sqlDbType)
{
switch (sqlDbType) {
case SqlDbType.BigInt : return typeof(long);
case SqlDbType.Binary : return typeof(byte[]);
case SqlDbType.Bit : return typeof(bool);
case SqlDbType.Char : return typeof(string);
case SqlDbType.DateTime : return typeof(DateTime);
case SqlDbType.Decimal : return typeof(decimal);
case SqlDbType.Float : return typeof(double);
case SqlDbType.Image : return typeof(byte[]);
case SqlDbType.Int : return typeof(int);
case SqlDbType.Money : return typeof(decimal);
case SqlDbType.NChar : return typeof(string);
case SqlDbType.NText : return typeof(string);
case SqlDbType.NVarChar : return typeof(string);
case SqlDbType.Real : return typeof(Single);
case SqlDbType.UniqueIdentifier : return typeof(Guid);
case SqlDbType.SmallDateTime : return typeof(DateTime);
case SqlDbType.SmallInt : return typeof(Int16);
case SqlDbType.SmallMoney : return typeof(decimal);
case SqlDbType.Text : return typeof(string);
case SqlDbType.Timestamp : return typeof(byte[]);
case SqlDbType.TinyInt : return typeof(byte);
case SqlDbType.VarBinary : return typeof(byte[]);
case SqlDbType.VarChar : return typeof(string);
case SqlDbType.Variant : return typeof(object);
default : throw ExceptionHelper.InvalidSqlDbType((int)sqlDbType);
}
}
protected internal sealed override object ConvertValue(object value) { // can not convert null or DbNull to other types if (value == null || value == DBNull.Value) { return(value); } // .NET throws an exception to the user. object convertedValue = value is IConvertible?Convert.ChangeType(value, SqlConvert.SqlDbTypeToValueType(SqlDbType)) : value; return(convertedValue); }