dotConnect for PostgreSQL Documentation
PgSqlDataReader Class
Members  Example  See Also  support@devart.com
Devart.Data.PostgreSql Namespace : PgSqlDataReader Class

Reads a forward-only stream of rows from PostgreSQL.

Inheritance Hierarchy

System.Object
   System.MarshalByRefObject
      System.Data.Common.DbDataReader
         Devart.Common.DbDataReaderBase
            Devart.Data.PostgreSql.PgSqlDataReader

Syntax

Visual Basic (Declaration) 
Public Class PgSqlDataReader 
   Inherits Devart.Common.DbDataReaderBase
   Implements IEnumerableIDataReaderIDataRecordIDisposable 

Remarks

To create a PgSqlDataReader, you must call the ExecuteReader method of the PgSqlCommand object, rather than directly using a constructor.

System.Data.Common.DbDataReader.IsClosed and RecordsAffected are the only properties that you can call after the PgSqlDataReader is closed. In some cases, you must call Close before you can call RecordsAffected.

When protocol is ProtocolVersion.Ver20, the following restriction takes place. While the PgSqlDataReader is in use, the associated PgSqlConnection is busy serving the PgSqlDataReader, and no other operations can be performed on the PgSqlConnection other than closing it. This is the case until the Close method of the PgSqlDataReader is called. For example, you cannot retrieve output parameters until you call Close.

Example

The following example creates a PgSqlConnection, a PgSqlCommand, and a PgSqlDataReader. The example reads through the data, writing it out to the console. Finally, the example closes the PgSqlDataReader, then the PgSqlConnection.
C#csharpCopy Code
public void ReadMyData(string myConnString)  {
        PgSqlConnection pgConnection = new PgSqlConnection(myConnString);
        PgSqlCommand pgCommand = (PgSqlCommand)pgConnection.CreateCommand();
        pgCommand.CommandText = "SELECT DeptNo, DName, Loc FROM Test.Dept";
        pgConnection.Open();
        PgSqlDataReader pgReader = pgCommand.ExecuteReader();
        try {
                // Always call Read before accessing data.
                while (pgReader.Read()) {
                Console.WriteLine(pgReader.GetInt32(0).ToString() + " " + 
                pgReader.GetString(1) + " " + pgReader.GetString(2));
        }
        }
        finally {
                // always call Close when done reading.
                pgReader.Close();

                // Close the connection when done with it.
                pgConnection.Close();
        }
}
C#Visual BasicCopy Code
Public Sub ReadMyData(ByVal myConnString As String)
        Dim pgConnection As New PgSqlConnection(myConnString)
        Dim pgCommand As PgSqlCommand = pgConnection.CreateCommand()
                pgCommand.CommandText = "SELECT DeptNo, DName, Loc FROM Test.Dept"
        pgConnection.Open()
        Dim pgReader As PgSqlDataReader = pgCommand.ExecuteReader()
        Try
                ' Always call Read before accessing data.
                While pgReader.Read()
                        Console.WriteLine(String.Concat(pgReader.GetInt32(0).ToString(), " ", _
                        pgReader.GetString(1), " ", pgReader.GetString(2)))
                End While
        Finally
                ' always call Close when done reading.
                pgReader.Close()

                        ' Close the connection when done with it.
                        pgConnection.Close()
        End Try
End Sub

Requirements

Namespace: Devart.Data.PostgreSql

Platforms:Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family, Windows 7, Windows 8, Windows 10, Windows Server 2012 family.

See Also