Pages

Monday, December 13, 2010

oracle.dataaccess conversion from type oracledecimal to type integer is not valid

Imports System
Imports System.Data
Imports Oracle.DataAccess.Client
 
Module Module1
  Sub Main()
    Dim con As New OracleConnection("user id=scott;password=tiger;data source=orademo")
    con.Open()
 
    Dim cmd As OracleCommand = New OracleCommand("getoutnum", con)
    cmd.CommandType = CommandType.StoredProcedure
 
    Dim p1 As New OracleParameter
    'this will not work as expected with .NET 2.x and higher and ODP.NET
    'p1.OracleDbType = OracleDbType.Int32
 
    'use DbType and not OracleDbType to get the parameter as a .NET data type
    p1.DbType = DbType.Int32
    p1.Direction = ParameterDirection.Output
 
    cmd.Parameters.Add(p1)
 
    cmd.ExecuteNonQuery()
 
    Try
      Dim a As Integer = p1.Value
      Console.WriteLine("val is {0}", a)
    Catch ex As Exception
      Console.WriteLine(ex.Message)
    End Try
 
  End Sub
End Module

No comments:

Post a Comment