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

Reads a forward-only stream of rows from PostgreSQL.

Inheritance Hierarchy



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


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.


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";
        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.

                // Close the connection when done with it.
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"
        Dim pgReader As PgSqlDataReader = pgCommand.ExecuteReader()
                ' 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
                ' always call Close when done reading.

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


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