zoukankan      html  css  js  c++  java
  • 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);
    			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;
    }
    
  • 相关阅读:
    session和cookie
    数据库备份
    使用pip安装.whl文件时出现is not a supported wheel on this platform的解决办法
    multiprocessing模块
    threading模块
    python中多线程相关
    python中实现单例模式
    Flask-SQLAlchemy相关与Flask-Migrate相关
    redis模块
    Flask-Login中装饰器@login_manager.user_loader的作用及原理
  • 原文地址:https://www.cnblogs.com/davinci/p/1654139.html
Copyright © 2011-2022 走看看