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 pgSqlConnectionString)
{
PgSqlConnection pgSqlConnection = new PgSqlConnection(pgSqlConnectionString);
PgSqlCommand pgSqlCommand = new PgSqlCommand(mySelectQuery, pgSqlConnection);
pgSqlCommand.Connection.Open();
PgSqlDataReader pgSqlReader = pgSqlCommand.ExecuteReader();
try
{
while(pgSqlReader.Read())
{
Console.WriteLine(pgSqlReader.GetString(0));
}
}
finally
{
pgSqlReader.Close();
pgSqlConnection.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()
Try
While pgSqlReader.Read()
Console.WriteLine(pgSqlReader.GetString(0))
End While
Finally
pgSqlReader.Close()
pgSqlConnection.Close()
End Try
End Sub |