dotConnect for PostgreSQL Documentation
Devart.Data.PostgreSql Namespace / PgSqlCommand Class
Members Example

On this page
    PgSqlCommand Class
    On this page
    Represents a SQL statement or stored procedure to execute against PostgreSQL.
    Syntax
    Remarks
    The PgSqlCommand class provides the following methods for executing commands against the PostgreSQL database:
    Item Description
    ExecuteReader Executes commands that return rows.
    Devart.Common.DbCommandBase.ExecutePageReader Returns a specific subset of rows when paging through the results of a query.
    ExecuteNonQuery Executes SQL commands such as INSERT, DELETE, UPDATE.
    ExecuteScalar Retrieves a single value (for example, an aggregate value) from a data source.

    If execution of the command results in a fatal PgSqlException, the PgSqlConnection may close. However, the user can reopen the connection and continue.

    This class supports cross-form data binding with the InterForm Technology.

    Example
    The following example uses the ExecuteReader method of PgSqlCommand, along with PgSqlDataReader and PgSqlConnection, to select rows from a table.
    public void ReadMyData(string myConnString)
    {
      string mySelectQuery = "SELECT DeptNo, DName FROM Test.Dept";
      PgSqlConnection pgSqlConnection = new PgSqlConnection(myConnString);
      PgSqlCommand pgSqlCommand = new PgSqlCommand(mySelectQuery,pgSqlConnection);
      pgSqlConnection.Open();
      PgSqlDataReader pgSqlReader = pgSqlCommand.ExecuteReader();
      try
      {
        while (pgSqlReader.Read())
        {
          Console.WriteLine(pgSqlReader.GetInt32(0).ToString() + ", " + pgSqlReader.GetString(1));
        }
      }
      finally
      {
      // always call Close when done reading.
      pgSqlReader.Close();
      // always call Close when done reading.
      pgSqlConnection.Close();
      }
    }
    Public Sub ReadMyData(myConnString As String)
      Dim mySelectQuery As String = "SELECT DeptNo, DName FROM Test.Dept"
      Dim pgSqlConnection As New PgSqlConnection(myConnString)
      Dim pgSqlCommand As New PgSqlCommand(mySelectQuery, pgSqlConnection)
      pgSqlConnection.Open()
      Dim pgSqlReader As PgSqlDataReader = pgSqlCommand.ExecuteReader()
      Try
        While pgSqlReader.Read()
          Console.WriteLine(pgSqlReader.GetInt32(0).ToString() + ", " _
            + pgSqlReader.GetString(1))
        End While
      Finally
          ' always call Close when done reading.
          pgSqlReader.Close()
          ' always call Close when done with connection.
          pgSqlConnection.Close()
      End Try
    End Sub
    Inheritance Hierarchy

    System.Object
       System.MarshalByRefObject
          System.ComponentModel.Component
             System.Data.Common.DbCommand
                Devart.Common.DbCommandBase
                   Devart.Data.PostgreSql.PgSqlCommand

    See Also