dotConnect for PostgreSQL Documentation
Devart.Data.PostgreSql Namespace / PgSqlDataReader Class / Read Method
Example

In This Topic
    Read Method (PgSqlDataReader)
    In This Topic
    Advances the PgSqlDataReader 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 PgSqlDataReader is prior to the first record. Therefore, you must call Read to begin accessing any data.

    While the PgSqlDataReader is in use, the associated PgSqlConnection is busy serving it 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.
    public void ReadMyData(string myConnString)
    {
      string mySelectQuery = "SELECT DeptNo, DName FROM Test.Dept";
      PgSqlConnection pgConnection = new PgSqlConnection(myConnString);
      PgSqlCommand pgCommand = new PgSqlCommand(mySelectQuery,pgConnection);
      pgConnection.Open();
      PgSqlDataReader pgReader;
      pgReader = pgCommand.ExecuteReader();
      // Always call Read before accessing data.
      while (pgReader.Read()) {
        Console.WriteLine(pgReader.GetInt32(0) + ", " + pgReader.GetString(1));
      }
      // always call Close when done reading.
      pgReader.Close();
      // Close the connection when done with it.
      pgConnection.Close();
    }
    Public Sub ReadMyData(myConnString As String)
      Dim mySelectQuery As String = "SELECT DeptNo, DName FROM Test.Dept"
      Dim pgConnection As New PgSqlConnection(myConnString)
      Dim pgCommand As New PgSqlCommand(mySelectQuery, pgConnection)
      pgConnection.Open()
      Dim pgReader As PgSqlDataReader
      pgReader = pgCommand.ExecuteReader()
      ' Always call Read before accessing data.
      While pgReader.Read()
        Console.WriteLine(pgReader.GetInt32(0).ToString() + ", " _
          + pgReader.GetString(1))
      End While
      ' always call Close when done reading.
      pgReader.Close()
      ' Close the connection when done with it.
      pgConnection.Close()
    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