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

On this page
    Close Method (PgSqlDataReader)
    On this page
    Closes the PgSqlDataReader object.
    Syntax
    'Declaration
     
    Public Overrides Sub Close() 
    public override void Close()
    Remarks
    You must explicitly call the Close method after you have finished working with the PgSqlDataReader in order to use the associated PgSqlConnection for any other purpose.
    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 pgSqlConnection = new PgSqlConnection(myConnString);
      PgSqlCommand pgSqlCommand = new PgSqlCommand(mySelectQuery,pgSqlConnection);
      pgSqlConnection.Open();
      PgSqlDataReader pgSqlReader;
      pgSqlReader = pgSqlCommand.ExecuteReader();
      // Always call Read before accessing data.
      while (pgSqlReader.Read()) {
        Console.WriteLine(pgSqlReader.GetInt32(0) + ", " + pgSqlReader.GetString(1));
      }
      // always call Close when done reading.
      pgSqlReader.Close();
      // Close the connection when done with it.
      pgSqlConnection.Close();
    }
    Public Sub ReadMyData(myConnString As String)
      Dim mySelectQuery As String = "SELECT DeptNo, DName FROM Test.Dept"
      Dim pgSqlConnection As New PgSqlConnection(myConnString)
      Dim pgSqlCommand As New PgSqlCommand(mySelectQuery, pgSqlConnection)
      pgSqlConnection.Open()
      Dim pgSqlReader As PgSqlDataReader
      pgSqlReader = pgSqlCommand.ExecuteReader()
      ' Always call Read before accessing data.
      While pgSqlReader.Read()
        Console.WriteLine(pgSqlReader.GetInt32(0).ToString() + ", " _
          + pgSqlReader.GetString(1))
      End While
      ' always call Close when done reading.
      pgSqlReader.Close()
      ' Close the connection when done with it.
      pgSqlConnection.Close()
    End Sub
    See Also