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 pgSqlConnectionString)
{
PgSqlConnection pgSqlConnection = new PgSqlConnection(pgSqlConnectionString);
PgSqlCommand pgSqlCommand = new PgSqlCommand(mySelectQuery, pgSqlConnection);
pgSqlCommand.Connection.Open();
PgSqlDataReader pgSqlReader = pgSqlCommand.ExecuteReader(CommandBehavior.CloseConnection);
while(pgSqlReader.Read())
{
Console.WriteLine(pgSqlReader.GetString(0));
}
pgSqlReader.Close();
} |
|
|---|
Public Sub CreatePgSqlDataReader(mySelectQuery As String, _
pgSqlConnectionString As String)
Dim pgSqlConnection As New PgSqlConnection(pgSqlConnectionString)
Dim pgSqlCommand As New PgSqlCommand(mySelectQuery, pgSqlConnection)
pgSqlCommand.Connection.Open()
Dim pgSqlReader As PgSqlDataReader = pgSqlCommand.ExecuteReader(CommandBehavior.CloseConnection)
While pgSqlReader.Read()
Console.WriteLine(pgSqlReader.GetString(0))
End While
pgSqlReader.Close()
End Sub |