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

In This Topic
    PgSqlCommand Class
    In This Topic
    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 pgConnection = new PgSqlConnection(myConnString);
      PgSqlCommand pgCommand = new PgSqlCommand(mySelectQuery,pgConnection);
      pgConnection.Open();
      PgSqlDataReader pgReader = pgCommand.ExecuteReader();
      try
      {
        while (pgReader.Read())
        {
          Console.WriteLine(pgReader.GetInt32(0).ToString() + ", " + pgReader.GetString(1));
        }
      }
      finally
      {
      // always call Close when done reading.
      pgReader.Close();
      // always call Close when done reading.
      pgConnection.Close();
      }
    }
    Public Sub ReadMyData(myConnString As String)
      Dim mySelectQuery As String = "SELECT DeptNo, DName FROM Test.Dept"
      Dim pgConnection As New PgSqlConnection(myConnString)
      Dim pgCommand As New PgSqlCommand(mySelectQuery, pgConnection)
      pgConnection.Open()
      Dim pgReader As PgSqlDataReader = pgCommand.ExecuteReader()
      Try
        While pgReader.Read()
          Console.WriteLine(pgReader.GetInt32(0).ToString() + ", " _
            + pgReader.GetString(1))
        End While
      Finally
          ' always call Close when done reading.
          pgReader.Close()
          ' always call Close when done with connection.
          pgConnection.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