Microsoft.NET and Oracle data access: Conversion f

2019-08-04 00:22发布

问题:

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()