DbType与Type之间的转换1. DbType ==>Type:
public static DbType TypeToDbType(Type t)
{
DbType dbt;
try
{
dbt = (DbType)Enum.Parse(typeof(DbType), t.Name);
}
catch
{
dbt = DbType.Object;
}
return dbt;
}
2. Type ==> DbType:
static Type ConvertType(DbType dbType)
{
Type toReturn = typeof(DBNull);
switch (dbType)
{
case DbType.UInt64:
toReturn = typeof(UInt64);
break;
case DbType.Int64:
toReturn = typeof(Int64);
break;
case DbType.Int32:
toReturn = typeof(Int32);
break;
case DbType.UInt32:
toReturn = typeof(UInt32);
break;
case DbType.Single:
toReturn = typeof(float);
break;
case DbType.Date:
case DbType.DateTime:
case DbType.Time:
toReturn = typeof(DateTime);
break;
case DbType.String:
case DbType.StringFixedLength:
case DbType.AnsiString:
case DbType.AnsiStringFixedLength:
toReturn = typeof(string);
break;
case DbType.UInt16:
toReturn = typeof(UInt16);
break;
case DbType.Int16:
toReturn = typeof(Int16);
typeof的用法break;
case DbType.SByte:
toReturn = typeof(byte);
break;
case DbType.Object:
toReturn = typeof(object);
break;
case DbType.VarNumeric:
case DbType.Decimal:
toReturn = typeof(decimal); break;
case DbType.Currency:
toReturn = typeof(double); break;
case DbType.Binary:
toReturn = typeof(byte[]); break;
case DbType.Double:
toReturn = typeof(Double); break;
case DbType.Guid:
toReturn = typeof(Guid); break;
case DbType.Boolean:
toReturn = typeof(bool);
break;
}
return toReturn;
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论