问题
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
When i read it with Oracle-Datareader i get
1
1,10 <-
1,12
1,1230 <-
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?
EDIT:
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()
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.
回答1:
It's in the C# and not in the DB.
From the Documentation:
If format is null or an empty string, the return value of this instance is formatted with the general numeric format specifier (G)
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");
Where dr is my OracleDataReader
来源:https://stackoverflow.com/questions/10981003/how-can-i-get-oracle-number-values-to-net-without-zeros