一般如何格式化 OracleNumber
我为 Oracle 构建了一个小型查询工具,具有 CSV 导出功能,并使用 OracleDataAdapter 来填充 DataGrid (WinForms) 中显示的数据集。起初,我使用 .NET 类型(DateTime、小数、字符串...),但在某些情况下,由于 Oracle 中的精度较高(NUMBER(30,10)
),我遇到了溢出异常。因此,我必须在 OracleDataAdapter 中设置属性 ReturnProviderSpecificTypes = true
,因此现在它使用 OracleClient (OracleNumber、OracleBoolean、OracleString,...) 类型。
问题是,当我在 nl-BE 区域时,所有内容都始终本地化(在屏幕上和 CSV 输出期间)为 en-US 格式(我们使用逗号作为小数分隔符,点作为千位分隔符)。顺便说一句,CSV 中的列分隔符是分号,因此十进制数字中的逗号不会受到干扰。
那么有没有办法以某种方式覆盖这些类型的 ToString 方法呢?某种注入格式化引擎?
谢谢
I built a small query tool for Oracle with CSV export function with an OracleDataAdapter to fill a dataset that is displayed in a DataGrid (WinForms). At first I used .NET types (DateTime, decimal, string,...) but I got overflow exceptions in some cases because of larger precision in Oracle (NUMBER(30,10)
). Therefore I had to set the property ReturnProviderSpecificTypes = true
in the OracleDataAdapter so now it uses OracleClient (OracleNumber, OracleBoolean, OracleString,...) types instead.
The problem is everything is always localized (on screen and during CSV output) to en-US formats while I'm in nl-BE region (we use comma as decimal separator and point as thousand separator). The column separator in CSV is semicolon btw, so there's no interference with the comma in decimal numbers.
So is there a way to override the ToString method in a way for those types? Some sort of injecting a formatting engine?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
ALTER SESSION SET NLS_...
。查看: http://download.oracle.com/docs /cd/B28359_01/olap.111/b28126/dml_options072.htm有一个示例,说明它如何使用点广告小数点和空格作为千位分隔符(另请注意日期时间设置):
You can use
ALTER SESSION SET NLS_...
. Look: http://download.oracle.com/docs/cd/B28359_01/olap.111/b28126/dml_options072.htmThere is example of how it works with dot ad decimal point and space as thousand separator (also note datetime setting):
似乎没有好的通用方法可以做到这一点。对于 CSV 输出,我找到了解决方法,但不适用于屏幕上的输出。
在输出期间,我必须测试 OracleNumber 类型的每个值(无论如何我都必须测试 INullable)并相应地进行转换。然后有两个选项:
或者
对于屏幕上的输出,我们可以使用类似的技术,从 OracleDataAdapter 填充的数据表中加载内存中的新数据表,然后使用 .NET CLR 类型,但由于结果集可能非常大,因此可能这是一个危险而沉重的技巧,所以我们就用英文符号来生活......
Seems like there is no good generic way to do this. For the CSV output I found a workaround but not for the output on screen.
During output I have to test every value for type OracleNumber (I have to test for INullable anyway) and cast it accordingly. Then there are two options:
or
For output on screen we could use a similar technique and load a new DataTable in memory from the one filled by the OracleDataAdapter but then with .NET CLR types, but since the resultsets could be very large, that could be a dangerously heavy trick to do, so we'll just live with english notation there...
33.3333,666667
添加:
请参阅 http://cs.felk .cvut.cz/10gr2/win.102/b14307/OracleGlobalizationClass.htm#i1010070 了解可能的参数
33.3333,666667
ADDED:
See http://cs.felk.cvut.cz/10gr2/win.102/b14307/OracleGlobalizationClass.htm#i1010070 for the possible parameters