ExecuteReader(CommandBehavior) Method
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
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