BUG: The scale value for Oracle numeric parameter is ignored (317528)



The information in this article applies to:

  • Microsoft ADO.NET (included with the .NET Framework)
  • Microsoft ADO.NET (included with the .NET Framework 1.1)
  • Microsoft Visual Basic .NET (2002)
  • Microsoft Visual Basic .NET (2003)

This article was previously published under Q317528
This article refers to the following Microsoft .NET Framework Class Library namespaces:
  • System.Data
  • System.Data.OleDb

SYMPTOMS

When you set the scale for a parameter of type NUMBER, it does not affect the value of the parameter that is passed to the database.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

MORE INFORMATION

If you set the parameter scale to three and the parameter value is 2.1234, the last number of the parameter value (in this example, "4") is not truncated and it is passed to the database. However, if the column that is going to be updated in the database also has a scale of three, the last number in the parameter value is truncated by the database.

Steps to reproduce the problem

  1. Create a new Visual Basic Windows Application project. Form1 is added to the project by default.
  2. Add the following code to the top of the Code window:
    Imports System.Data.OleDb
  3. Add a Button control to Form1.
  4. Double-click the Button control to bring up the Button1_Click event in the Code window.
  5. Add the following code to the Button1_Click event of Form1:
            Dim connection1 As New OleDbConnection("Provider=MSDAORA;Data Source=myOracle;User ID=myUserID;Password=myPassword")
            connection1.Open()
            Dim cmd As New OleDbCommand()
            cmd.Connection = connection1
            cmd.CommandText = "create table Testscale(col_float_1 float PRIMARY KEY, col_number_4 numeric(28,4))"
            cmd.ExecuteNonQuery()
    
            Dim command2 = New OleDbCommand("insert into Testscale(col_float_1, col_number_4) values(?,?)", connection1)
            command2.Parameters.Add("@col_float_1", OleDbType.Double).Value = 1.0
    
            command2.Parameters.Add("@col_number_4", OleDbType.Numeric)
            command2.Parameters("@col_number_4").Precision = 28
            command2.Parameters("@col_number_4").Scale = 3
            command2.Parameters("@col_number_4").Value = New Decimal(25.50254)
    
            Dim myx As Exception
            Try
                command2.ExecuteNonQuery()
            Catch myx
                MessageBox.Show(myx.Message.ToString)
            End Try
    
            Dim Reader2 As OleDbDataReader
            cmd.CommandText = "select * from Testscale"
            Try
                Reader2 = cmd.ExecuteReader
    
                
                Dim x As Integer
                Do While Reader2.Read()
                    For x = 0 To Reader2.FieldCount - 1
                        MessageBox.Show(Reader2(x) & " ")
                    Next
                    Console.WriteLine()
                Loop
    
            Finally
                'If Reader Is System.DBNull Then
                Reader2.Close()
                'End If
            End Try
  6. Modify the OleDbConnection string as appropriate for your environment.
  7. Press the F5 key to compile and to run the application.
  8. Click OK when you receive a dialog box that contains the value of the first field. (In this example, the value "1" appears.)
  9. A dialog box that contains the second field will appear. Notice that the parameter value is "25.50254" with a scale of three, but the parameter value "25.5025" was inserted into the database. Even with a scale of three for the parameter, 4 digits were passed to the database. The last digit of the parameter value was truncated by the database because the underlying column has a scale of four.

Modification Type:MinorLast Reviewed:3/13/2006
Keywords:kbvs2002sp1sweep kbbug kbnofix kbSystemData KB317528 kbAudDeveloper