简体   繁体   English

如何将Oracle数字值不带零的.NET?

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

i try to read Data from an Oracle-Database. 我尝试从Oracle数据库读取数据。 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 1,1

1,12 1,12

1,123 1,123

When i read it with Oracle-Datareader i get 当我用Oracle-Datareader读取它时

1 1个

1,10 <- 1,10 <-

1,12 1,12

1,1230 <- 1,1230 <-

Everytime the decimal places are 1,3,5,7 long it adds one 0 in the result. 每次小数位长1、3、5、7时,结果将加1。 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. 因为使用dr.GetDecimal()的方式仅排除用于行索引的数字。

It's in the C# and not in the DB. 它在C#中,不在数据库中。

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) 如果format为null或空字符串,则使用通用数字格式说明符(G)格式化此实例的返回值。

The general format contain the zero you want to avoid. general format包含要避免的零。
If you want to remove it, just do: 如果要删除它,请执行以下操作:

string sd = dr.GetDecimal(0).ToString("G0");

Where dr is my OracleDataReader 博士在哪里我的OracleDataReader

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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