填充数据集时,ODP.net Oracle十进制数字精度问题.例外:算术运算导致溢出 [英] ODP.net Oracle Decimal Number precision problem when filling a dataset. Exception: Arithmetic operation resulted in an overflow

查看:83
本文介绍了填充数据集时,ODP.net Oracle十进制数字精度问题.例外:算术运算导致溢出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用c#.net 2(Visual Studio 2005 SP1),尝试用来自Oracle10g数据库的select * from表中的结果填充数据集.无法在此客户端站点上更改.net框架,IDE和数据库 .

I am working in c# .net 2 (Visual Studio 2005 SP1) attempting to fill a dataset with the results from a select * from table from an Oracle10g database. The .net framework, IDE and database cannot be changed at this client site.

我正在使用 ODP.net提供程序进行连接,dll版本为 2.102.2.20

I'm connecting using the ODP.net provider the dll version is 2.102.2.20

当我运行fill命令时,我得到一个异常:

When I run the fill command I get an Exception:

算术运算导致溢出

此外,如果我尝试在Visual Studio设计器中查看有问题的列(显示表数据"),则表中该列的每一行都会得到 .如果我的查询选择了其他带有整数的列(例如,省略了该列),则该代码可完美运行.

Also if I attempt to view the offending column in the Visual Studio designer (Show Table Data) I get for every row for this column in the table. The code works perfectly if my query selects other columns with integers for example omitting this column.

当我从Toad在数据库中查看问题列时,它看起来很好,数据如下:

The column in question looks fine when I view it in the database from Toad, data looks like:

919.742866695572

我需要精度,因为蒙特卡洛模拟需要它.

I need the precision as it's required for a monte carlo simulation.

如果不是使用数据适配器填充数据表,而是使用datareader并调用dataReader.getValue(columnIndex),则会遇到相同的错误,但是如果我调用dataReader.GetOracleDecimal(columnIndex),则会得到所需的结果,没有错误.

If instead of using a data adapter to fill the datatable I use a datareader and call dataReader.getValue(columnIndex) I get the same error but if I call dataReader.GetOracleDecimal(columnIndex) then I get the result I am looking for, no error.

我宁愿使用数据适配器并填充数据集(请注意,这些是未类型化的数据集,因为我无法从Oracle数据库获得自动生成的强类型化数据集来工作).我不想使用datareader并浏览结果(挑选列值),因为我试图将其写为一种通用方法,以适用于许多情况,而无论列数,十进制列的索引是否需要特定按数据类型接听电话.

I would rather use data adapter and filling a dataset (note these are untyped datasets as I couldn't get autogenerated strongly typed datasets to work from an oracle db). I don't want to use datareader and walk through the results (pick out the column values) as I am trying to write this as a generic method to work for many scenarios regardless of number of columns, index of decimal columns that would require specific get calls by datatype.

任何人都可以帮忙吗?我可以使用新版本的ODP.net dll连接到较旧的 Oracle10g 数据库吗?我想知道这是否有帮助.

Can anyone help? Can I use new versions of the ODP.net dlls to connect to the older Oracle10g database? am wondering if this will help.

谢谢

推荐答案

问题是结果值的精度太高而无法转换为System.Decimal,而不会造成任何数据丢失.我忘记了允许的确切数字位数,但是大约是18位左右.将结果值舍入为这么多位数是否可以接受?在您给出的示例中,一个 round(MyColumn,15)左右就足够了.

The problem is that the precision of the result value is too high to convert to a System.Decimal without some data loss. I forget the exact number of digits allowed, but it is around 18 or so. Is it acceptable to round() the result value to that many digits? In the example you gave, a round(MyColumn, 15) or so should be sufficient...

这篇关于填充数据集时,ODP.net Oracle十进制数字精度问题.例外:算术运算导致溢出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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