Oracle数字到C#十进制 [英] Oracle number to C# decimal

查看:271
本文介绍了Oracle数字到C#十进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有几个主题和帖子就这个问题在互联网和我读过他们的(不是每一篇文章,我不得不承认),但没有人没有完全满足我。

I know there are several threads and posts regarding this issue in the internet and I've read them (not every article, I have to admit) but none of them did fully satisfy me.

我的情况:结果
我使用ODP.net(DLL版本2.111.6.0)访问Oracle数据库(版本10 + 11)和一个DataReader检索数据( .NET 3.5,C#)。

My situation:
I'm using ODP.net (dll version 2.111.6.0) to access the Oracle DB (version 10 + 11) and a DataReader to retrieve the data (.NET 3.5, C#).

出现System.OverflowException(算术运算导致溢出。)<使用此代码的结果/ p>

Using this code results in a 'System.OverflowException (Arithmetic operation resulted in an overflow.)'


decimal.TryParse(oraReader.GetOracleDecimal(0).Value.ToString(), 
  NumberStyles.Any, null, out parsedOraDecimal)

和中值这一个结果 3, 000000000000000000000000000000000000000000000000000000000E-126


decimal.TryParse(oraReader.GetOracleValue(0).ToString(), 
  NumberStyles.Any, null, out parsedOraDecimal)

现在我必须找到某种方式检索和正确评价这个值 - 数据库也由这是在我的掌握中的其他应用程序使用,以便改变不会有可能的。

Now I have to find some way to retrieve and evaluate this value properly - the DB is also used from other apps which are out of my control so changes there are not possible.

在我的C#转换的类型从十进制'到'双'的代码也不是一个真正的选择。

Converting the types in my C# code from 'decimal' to 'double' is also not really an option.

任何想法?

谢谢为您提供帮助!

问候,
robert.oh。

Regards, robert.oh.

推荐答案

我刚做了一个类似的问题,并试图改变OracleDataAdapter返回甲骨文特定类型(data_adapter.ReturnProviderSpecificTypes =真正的办法; ),但是这仅仅是一个皮塔饼,你最终铸造OracleStrings回字符串,等等。

I just had a similar issue, and tried the approach of changing the OracleDataAdapter to return Oracle specific types ( data_adapter.ReturnProviderSpecificTypes = true; ), but this is just a PITA, you end up casting OracleStrings back to strings, etc.

在最后我解决它做的精度在SQL语句四舍五入使用Oracle的圆形功能:

In the end I solved it by doing the precision rounding in the SQL statement using Oracle's round function:

SELECT round( myfield, 18 ) FROM mytable

DOTNET然后将愉快地转换成数字为十进制。

Dotnet will then happily convert the figure to a decimal.

这篇关于Oracle数字到C#十进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆