dotConnect for Oracle Documentation
Devart.Data.Oracle Namespace / OracleObject Class
Members Example

In This Topic
    OracleObject Class
    In This Topic
    Represents a client-side cached Oracle object of type defined by user.
    Syntax
    Remarks
    To retrieve values of object attributes OracleObject class uses Item indexed property.

    You can create an instance of OracleObject by one of the following ways:

    - execute a query that returns an object as one of the fields calling OracleDataReader.GetOracleObject method;

    - return an OracleObject instance as a parameter value of OracleDbType.Object type;

    - get the OracleObject as a value of owned OracleObject attribute.

    Also you can create an instance of OracleObject manually.

    You can use OracleObject to pass object as a parameter value.

    Note that OracleObject can be used in data binding with DataGrid as it implements IListSource interface.

    Example

    This example demonstrates how to retrieve OracleObject instance from server and display its elements. To create required type and table and fill it with data you can use the following script:

    CREATE TYPE TAddress AS OBJECT (
      Country VARCHAR2(30),
      City VARCHAR2(30),
      Street VARCHAR2(30),
      Apartment NUMBER
    );
    
    CREATE TABLE EmpObject (
      Code NUMBER PRIMARY KEY,
      Person VARCHAR2(40),
      Address TAddress,
      Job VARCHAR2(9)
    );
    
    INSERT INTO EmpObject
      (Code, Person, Address, Job)
    VALUES
      (1, 'SMITH', TAddress('UK', 'London', 'Street', 12), 'CLERK');
    INSERT INTO EmpObject
      (Code, Person, Address, Job)
    VALUES
      (2, 'JONES', TAddress('USA', 'New York', 'Street', 418), 'MANAGER');
    INSERT INTO EmpObject
      (Code, Person, Address, Job)
    VALUES
      (3, 'SCOTT', TAddress('CANADA', 'Ottawa', 'Street', 26),'PRESIDENT');
    INSERT INTO EmpObject
      (Code, Person, Address, Job)
    VALUES
      (4, 'MARTIN', TAddress('FRANCE', 'Paris', 'Street', 162), 'ANALYST');
    

    OracleConnection connection = new OracleConnection("User Id=scott;Password=tiger;Data Source=ora");
    OracleCommand command = new OracleCommand("SELECT * FROM EmpObject", connection);
    connection.Open();
    OracleDataReader dataReader = command.ExecuteReader();
    try{
      int index = dataReader.GetOrdinal("Address");
      while (dataReader.Read()) {
        OracleObject oraObj = dataReader.GetOracleObject(index);
        if (!oraObj.IsNull) {
          string country = (string)oraObj["Country"];
          string city = (string)oraObj["City"];
          string street = (string)oraObj["Street"];
          decimal Apartment = (decimal)oraObj["Apartment"];
          Console.WriteLine(dataReader.GetString(0) + "   " + 
                            dataReader.GetString(1) + "   " + "Adress: " + country + 
                            ", " + city + ", " + street + ", "+ Apartment.ToString() 
                            + "   " + dataReader.GetString(3));
        }
      }
    }
    catch (Devart.Data.Oracle.OracleException ex) {
      Console.WriteLine(ex.Message);
    }
    finally{
      dataReader.Close();
      connection.Close();
    }
    Dim connection As New OracleConnection("User Id=scott;Password=tiger;Data Source=ora")
    Dim command As New OracleCommand("SELECT * FROM EmpObject", connection)
    connection.Open()
    Dim dataReader As OracleDataReader = command.ExecuteReader()
    Try
      Dim index As Integer = dataReader.GetOrdinal("Address")
      While dataReader.Read()
        Dim oraObj As OracleObject = dataReader.GetOracleObject(index)
        If Not oraObj.IsNull Then
          Dim country As String = oraObj("Country")
          Dim city As String = oraObj("City")
          Dim street As String = oraObj("Street")
          Dim Apartment As Decimal = oraObj("Apartment")
          Console.WriteLine(dataReader.GetString(0) & "   " & dataReader.GetString(1) & "   " & _
              "Adress: " & country & ", " & city & ", " & street & ", " & _
              Apartment.ToString() & "   " & dataReader.GetString(3))
        End If
      End While
    Catch ex As Devart.Data.Oracle.OracleException
      Console.WriteLine(ex.Message)
    Finally
      dataReader.Close()
      connection.Close()
    End Try
    Inheritance Hierarchy

    System.Object
       System.MarshalByRefObject
          Devart.Data.Oracle.OracleObject

    Requirements

    Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also