dotConnect for PostgreSQL Documentation
Devart.Data.PostgreSql Namespace / PgSqlCommand Class / ExecuteReader Method / ExecuteReader() Method
Example

ExecuteReader() Method
Sends the CommandText to the Connection and builds a PgSqlDataReader.
Syntax
'Declaration
 
Public Overloads Shadows Function ExecuteReader() As PgSqlDataReader
 

Return Value

A PgSqlDataReader object.
Remarks

When FetchAll property is false the following restriction takes place. While the PgSqlDataReader is in use, the associated PgSqlConnection is busy serving the PgSqlDataReader. While in this state, no operations can be performed on the PgSqlConnection except closing. This is the case until the PgSqlDataReader.Close method of the PgSqlDataReader is called.

Example
The following example creates a PgSqlCommand, 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 CreatePgSqlDataReader(string mySelectQuery,string pgConnectionString)
{
  PgSqlConnection pgConnection = new PgSqlConnection(pgConnectionString);
  PgSqlCommand pgCommand = new PgSqlCommand(mySelectQuery, pgConnection);
  pgCommand.Connection.Open();
  PgSqlDataReader pgReader = pgCommand.ExecuteReader();
  try
  {
    while(pgReader.Read())
    {
      Console.WriteLine(pgReader.GetString(0));
    }
  }
  finally
  {
    pgReader.Close();
    pgConnection.Close();
  }
}
Public Sub CreatePgSqlDataReader(mySelectQuery As String, _
pgConnectionString As String)
  Dim pgConnection As New PgSqlConnection(pgConnectionString)
  Dim pgCommand As New PgSqlCommand(mySelectQuery, pgConnection)
  pgCommand.Connection.Open()
  Dim pgReader As PgSqlDataReader = pgCommand.ExecuteReader()
  Try
    While pgReader.Read()
      Console.WriteLine(pgReader.GetString(0))
    End While
  Finally
    pgReader.Close()
    pgConnection.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