Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
ExecuteReader Method ()
Collapse the table of content
Expand the table of content

OracleCommand.ExecuteReader Method ()

.NET Framework 1.1
Note: This namespace, class, or member is supported only in version 1.1 of the .NET Framework.

Sends the CommandText to the Connection and builds an OracleDataReader.

[Visual Basic]
Overloads Public Function ExecuteReader() As OracleDataReader
[C#]
public OracleDataReader ExecuteReader();
[C++]
public: OracleDataReader* ExecuteReader();
[JScript]
public function ExecuteReader() : OracleDataReader;

Return Value

An OracleDataReader object.

Remarks

When the CommandType property is set to StoredProcedure, the CommandText property should be set to the name of the stored procedure. The command then executes this stored procedure when you call ExecuteReader.

More than one OracleDataReader can be open at any given time.

Example

[Visual Basic, C#, C++] The following example creates an OracleCommand, and then executes it by passing a string that is an SQL SELECT statement, and a string to use to connect to the data source.

[Visual Basic] 
Public Sub CreateMyOracleDataReader(mySelectQuery As String, _
myConnectionString As String)
    Dim myConnection As New OracleConnection(myConnectionString)
    Dim myCommand As New OracleCommand(mySelectQuery, myConnection)
    myConnection.Open()
    Dim myReader As OracleDataReader = myCommand.ExecuteReader()
    Try
      While myReader.Read()
          Console.WriteLine(myReader.GetString(0))
      End While
    Finally
      myReader.Close()
      myConnection.Close()
    End Try
 End Sub

[C#] 
public void CreateMyOracleDataReader(string mySelectQuery,string myConnectionString) 
{
   OracleConnection myConnection = new OracleConnection(myConnectionString);
   OracleCommand myCommand = new OracleCommand(mySelectQuery, myConnection);
   myConnection.Open();
   OracleDataReader myReader = myCommand.ExecuteReader();
   try
   {
     while(myReader.Read()) 
     {
        Console.WriteLine(myReader.GetString(0));
     }
   }
   finally
   {
     myReader.Close();
     myConnection.Close();
   }
}

[C++] 
public:
 void CreateMyOracleDataReader(String* mySelectQuery,String* myConnectionString) 
 {
    OracleConnection* myConnection = new OracleConnection(myConnectionString);
    OracleCommand* myCommand = new OracleCommand(mySelectQuery, myConnection);
    myConnection->Open();
    OracleDataReader* myReader = myCommand->ExecuteReader();
    try
    {
      while(myReader->Read()) 
      {
         Console::WriteLine(myReader->GetString(0));
      }
    }
    __finally
    {
      myReader->Close();
      myConnection->Close();
    }
 }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

OracleCommand Class | OracleCommand Members | System.Data.OracleClient Namespace | OracleCommand.ExecuteReader Overload List

Show:
© 2015 Microsoft