dotConnect for PostgreSQL Documentation
Devart.Data.PostgreSql Namespace / PgSqlCommand Class / ExecuteReader Method / ExecuteReader(CommandBehavior) Method
One of the System.Data.CommandBehavior values.
Example

ExecuteReader(CommandBehavior) Method
Sends the CommandText to the Connection, and builds a PgSqlDataReader using one of the System.Data.CommandBehavior values.
Syntax
'Declaration
 
Public Overloads Shadows Function ExecuteReader( _
   ByVal behavior As CommandBehavior _
) As PgSqlDataReader
 

Parameters

behavior
One of the System.Data.CommandBehavior values.

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. The System.Data.CommandBehavior is then set to CloseConnection.
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(CommandBehavior.CloseConnection);
  while(pgReader.Read())
  {
    Console.WriteLine(pgReader.GetString(0));
  }
  pgReader.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(CommandBehavior.CloseConnection)
  While pgReader.Read()
    Console.WriteLine(pgReader.GetString(0))
  End While
  pgReader.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