简体   繁体   中英

How can i get Oracle number values to .NET without Zeros?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM