dotConnect for DB2 Documentation
Devart.Data.DB2 Namespace / DB2Command Class / ExecuteReader Method / ExecuteReader() Method
Example

In This Topic
    ExecuteReader() Method
    In This Topic
    Sends the CommandText to the Connection and builds a DB2DataReader.
    Syntax
    'Declaration
     
    Public Overloads Shadows Function ExecuteReader() As DB2DataReader
    public new DB2DataReader ExecuteReader()

    Return Value

    A DB2DataReader object.
    Example
    The following example creates a DB2Command, then executes it by passing a string that is SQL SELECT statement, and a string to use to connect to the data source.
    public void CreateDB2DataReader(string mySelectQuery,string db2ConnectionString)
    {
      DB2Connection db2Connection = new DB2Connection(db2ConnectionString);
      DB2Command db2Command = new DB2Command(mySelectQuery, db2Connection);
      db2Command.Connection.Open();
      DB2DataReader db2Reader = db2Command.ExecuteReader();
      try
      {
        while(db2Reader.Read())
        {
          Console.WriteLine(db2Reader.GetString(0));
        }
      }
      finally
      {
        db2Reader.Close();
        db2Connection.Close();
      }
    }
    Public Sub CreateDB2DataReader(mySelectQuery As String, _
    db2ConnectionString As String)
      Dim db2Connection As New DB2Connection(db2ConnectionString)
      Dim db2Command As New DB2Command(mySelectQuery, db2Connection)
      db2Command.Connection.Open()
      Dim db2Reader As DB2DataReader = db2Command.ExecuteReader()
      Try
        While db2Reader.Read()
          Console.WriteLine(db2Reader.GetString(0))
        End While
      Finally
        db2Reader.Close()
        db2Connection.Close()
      End Try
    End Sub
    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