Microsoft.NET and Oracle data access: Conversion from type OracleDecimal to type String is not valid

青春壹個敷衍的年華 提交于 2019-12-13 00:11:30

问题


I have the following ASP.NET program, which calls an Oracle stored procedure:

Dim objDBCon As New OracleConnection(strCon)
Try
    objDBCon.Open()
        Dim objDBCmd As New OracleCommand("Person.DeletePerson", objDBCon)
        objDBCmd.CommandType = CommandType.StoredProcedure

        Dim objParam As New OracleParameter
        objParam.ParameterName = "PersonID"
        objParam.OracleDbType = OracleDbType.Varchar2
        objParam.Direction = ParameterDirection.Input
        objParam.Value = PersonID
        objDBCmd.Parameters.Add(objParam)

        objParam = New OracleParameter
        objParam.ParameterName = "nReturn"
        objParam.OracleDbType = OracleDbType.Int64
        objParam.Direction = ParameterDirection.Output
        objDBCmd.Parameters.Add(objParam)

        objDBCmd.CommandTimeout = 30
        objDBCmd.ExecuteNonQuery()
        strResponse = objDBCmd.Parameters("nReturn").Value
Catch ex As Exception


Finally

'Cleanup code here

End Try

The code works perfectly in the live environment and on my old development PC. However, on my new development PC, an exception is thrown on the following line: strResponse = objDBCmd.Parameters("nReturn").Value. The exception is: "Conversion from type OracleDecimal to type String is not valid. If I change the data type of strResponse to 'Decimal', then the exception is: "Conversion from type OracleDecimal to type String is not valid". The development PC has the following installed: Windows 7, .NET framework 3.5, Visual Studio 2008, Oracle.DataAccess version 10.2.0.100 and version 2.112.1.0. I cannot find any information on this error. What does it mean?

Update I am wandering if it is because my new development pc is 64 bit windows


回答1:


Instead of setting:

objParam.OracleDbType = OracleDbType.Int64

Try:

objParam.DbType = System.Data.DbType.Int64

Also, you may need to change:

strResponse = objDBCmd.Parameters("nReturn").Value

To:

strResponse = objDBCmd.Parameters("nReturn").Value.ToString()

Or:

strResponse = objDBCmd.Parameters("nReturn").ToString()


来源:https://stackoverflow.com/questions/10627415/microsoft-net-and-oracle-data-access-conversion-from-type-oracledecimal-to-type

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!