/// <summary> /// 把数据类型映射到ADO数据类型 /// </summary> /// <param name="dataType"></param> /// <returns></returns> protected override int MapAdoType(IDataType dataType) { if (dataType == null) { return((int)ADOType.adInteger); } ADOType AdoType = (ADOType)Enum.Parse(typeof(ADOType), dataType.Type); if (AdoType == ADOType.adNumeric || AdoType == ADOType.adDecimal) { if ((dataType.Scale ?? 0) == 0) { AdoType = ADOType.adInteger; //没有小数位 } else if (((dataType.Scale ?? 0) <= 6)) //6位一下的小数 { AdoType = ADOType.adDouble; } else { AdoType = ADOType.adNumeric; } } return((int)AdoType); }
/// <summary> /// ADO类型转换为FieldType类型 /// </summary> /// <param name="adoType">ADO类型</param> /// <returns></returns> public static FieldType ConvertToFieldType(ADOType adoType) { switch (adoType) { case ADOType.adTinyInt: return(FieldType.Int); case ADOType.adSmallInt: return(FieldType.Int); case ADOType.adInteger: return(FieldType.Int); case ADOType.adBigInt: return(FieldType.Long); case ADOType.adUnsignedTinyInt: case ADOType.adUnsignedSmallInt: case ADOType.adUnsignedInt: return(FieldType.Int); case ADOType.adUnsignedBigInt: return(FieldType.Long); case ADOType.adDecimal: case ADOType.adNumeric: case ADOType.adSingle: case ADOType.adDouble: return(FieldType.Decimal); case ADOType.adDate: case ADOType.adDBDate: case ADOType.adDBTime: case ADOType.adDBTimeStamp: case ADOType.adFileTime: return(FieldType.DateTime); case ADOType.adBoolean: return(FieldType.Bit); case ADOType.adBSTR: case ADOType.adChar: case ADOType.adVarChar: case ADOType.adVarWChar: case ADOType.adLongVarWChar: case ADOType.cadWChar: case ADOType.adLongVarChar: return(FieldType.String); case ADOType.adVarBinary: case ADOType.adLongVarBinary: case ADOType.adBinary: return(FieldType.Binary); case ADOType.adEmpty: case ADOType.adUserDefined: case ADOType.adVariant: case ADOType.adIDispatch: case ADOType.adIUnknown: case ADOType.adGUID: case ADOType.adCurrency: case ADOType.adChapter: case ADOType.adPropVariant: default: { throw (new ArgumentException("不被支持的数据类型(" + adoType + ")!", "ConvertToNETFxType")); } } }