dotConnect for Oracle Documentation
Devart.Data.Oracle Namespace / OracleDataReader Class / Read Method
Example

On this page
    Read Method (OracleDataReader)
    On this page
    Advances the OracleDataReader to the next record.
    Syntax
    'Declaration
     
    Public Overrides Function Read() As Boolean
    public override bool Read()

    Return Value

    true if there are more rows; otherwise, false.
    Remarks
    The default position of the OracleDataReader is prior to the first record. Therefore, you must call Read to begin accessing any data.

    While the OracleDataReader is in use, the associated OracleConnection is busy serving it until you call Close.

    Example
    The following example creates a OracleConnection, a OracleCommand, and a OracleDataReader. The example reads through the data, writing it out to the console. Finally, the example closes the OracleDataReader, then the OracleConnection.
    public void ReadMyData(string myConnString)
    {
      string mySelectQuery = "SELECT DeptNo, DName FROM Test.Dept";
      OracleConnection oracleConnection = new OracleConnection(myConnString);
      OracleCommand oracleCommand = new OracleCommand(mySelectQuery,oracleConnection);
      oracleConnection.Open();
      OracleDataReader oracleReader;
      oracleReader = oracleCommand.ExecuteReader();
      // Always call Read before accessing data.
      while (oracleReader.Read()) {
        Console.WriteLine(oracleReader.GetInt32(0) + ", " + oracleReader.GetString(1));
      }
      // always call Close when done reading.
      oracleReader.Close();
      // Close the connection when done with it.
      oracleConnection.Close();
    }
    Public Sub ReadMyData(myConnString As String)
      Dim mySelectQuery As String = "SELECT DeptNo, DName FROM Test.Dept"
      Dim oracleConnection As New OracleConnection(myConnString)
      Dim oracleCommand As New OracleCommand(mySelectQuery, oracleConnection)
      oracleConnection.Open()
      Dim oracleReader As OracleDataReader
      oracleReader = oracleCommand.ExecuteReader()
      ' Always call Read before accessing data.
      While oracleReader.Read()
        Console.WriteLine(oracleReader.GetInt32(0).ToString() + ", " _
          + oracleReader.GetString(1))
      End While
      ' always call Close when done reading.
      oracleReader.Close()
      ' Close the connection when done with it.
      oracleConnection.Close()
    End Sub
    See Also