数据库有一字段,类型为money
使用DataReader读取的时候提示转换失败。decimal dec = objDataReader.GetDecimal(0);

解决方案 »

  1.   

    这个问题 解决方法有一个
    把money 类型转换为float类型看看
      

  2.   

    哦 你这样转换为decimal应该是没有问题的
      

  3.   

    参考: /// <summary>
            /// 数据库中与c#中的数据类型对照
            /// </summary>
            /// <param name="type"></param>
            /// <returns></returns>
            private string changetocsharptype(string type)
            {
                string reval = string.empty;
                switch (type.tolower())
                {
                    case "int":
                        reval = "int32";
                        break;
                    case "text":
                        reval = "string";
                        break;
                    case "bigint":
                        reval = "int64";
                        break;
                    case "binary":
                        reval = "system.byte[]";
                        break;
                    case "bit":
                        reval = "boolean";
                        break;
                    case "char":
                        reval = "string";
                        break;
                    case "datetime":
                        reval = "system.datetime";
                        break;
                    case "decimal":
                        reval = "system.decimal";
                        break;
                    case "float":
                        reval = "system.double";
                        break;
                    case "image":
                        reval = "system.byte[]";
                        break;
                    case "money":
                        reval = "system.decimal";
                        break;
                    case "nchar":
                        reval = "string";
                        break;
                    case "ntext":
                        reval = "string";
                        break;
                    case "numeric":
                        reval = "system.decimal";
                        break;
                    case "nvarchar":
                        reval = "string";
                        break;
                    case "real":
                        reval = "system.single";
                        break;
                    case "smalldatetime":
                        reval = "system.datetime";
                        break;
                    case "smallint":
                        reval = "int16";
                        break;
                    case "smallmoney":
                        reval = "system.decimal";
                        break;
                    case "timestamp":
                        reval = "system.datetime";
                        break;
                    case "tinyint":
                        reval = "system.byte";
                        break;
                    case "uniqueidentifier":
                        reval = "system.guid";
                        break;
                    case "varbinary":
                        reval = "system.byte[]";
                        break;
                    case "varchar":
                        reval = "string";
                        break;
                    case "variant":
                        reval = "object";
                        break;
                    default:
                        reval = "string";
                        break;
                }
                return reval;
            }