如何将Oracle数字值不带零的.NET? [英] How can i get Oracle number values to .NET without Zeros?
问题描述
我尝试从Oracle数据库读取数据. 问题是,在某些情况下,接收数据在数字后加零,而我不知道为什么会发生这种情况?!?
i try to read Data from an Oracle-Database. The problem is that in some cases the receiving data adds Zeros after the digit and i dont know why this happens?!?
例如,我想读取这样的数据
For example i want to read Data like this
1
1,1
1,12
1,123
当我使用Oracle-Datareader读取它时,我会得到
When i read it with Oracle-Datareader i get
1
1,10<-
1,12
1,1230<-
1,1230 <-
每次小数位长1、3、5、7时,其结果将加1. 但是为什么会这样呢? 有人知道这种问题吗?
Everytime the decimal places are 1,3,5,7 long it adds one 0 in the result. But why is this happening?? Does anyone know this kind of problem?
Dim cmd As OracleCommand = New OracleCommand(Select_Statement, Connection)
Dim dr As OracleDataReader
dr = cmd.ExecuteReader
While dr.Read()
If dr("C1").ToString = V1 Then
Me.Txt_1.Text = dr.GetDecimal(3).ToString("G0")
Me.Txt_2.Text = dr(c4)
Me.Txt_3.Text = dr(c5)
Me.Txt_4.Text = dr(c6)
End If
If dr("C2").ToString = V2 Then
Me.Txt_5.Text = dr(c3)
Me.Txt_6.Text = dr(c4)
Me.Txt_7.Text = dr(c5)
Me.Txt_8.Text = dr(c6)
End If
End While
dr.Close()
这是我从数据库读取数据的方式,如果有更好的方式,我会对一些提示感到满意!因为使用dr.GetDecimal()的方式仅排除用于行索引的数字.
This is the way i read the data from the database, if there is a better way i would be happy about some tips! Because the way with dr.GetDecimal() only excepts numbers for row indexing.
推荐答案
它在C#中,而不在DB中.
It's in the C# and not in the DB.
从文档:
如果format为null或空字符串,则此方法的返回值 实例使用通用数字格式说明符(G)格式化
If format is null or an empty string, the return value of this instance is formatted with the general numeric format specifier (G)
general format
包含要避免的零.
如果要删除它,只需执行以下操作:
The general format
contain the zero you want to avoid.
If you want to remove it, just do:
string sd = dr.GetDecimal(0).ToString("G0");
博士在哪里是我的OracleDataReader
Where dr is my OracleDataReader
这篇关于如何将Oracle数字值不带零的.NET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!