# Class NpgsqlBatchCommand

Namespace
  Npgsql

Assembly
  Npgsql.dll

Represents a single command within a DbBatch. A batch can be executed against a data source in a single round trip.

    public sealed class NpgsqlBatchCommand : DbBatchCommand

Inheritance
  object
  DbBatchCommand
  NpgsqlBatchCommand

Inherited Members
  object.Equals(object)
  object.Equals(object, object)
  object.GetHashCode()
  object.GetType()
  object.ReferenceEquals(object, object)

## Constructors

### NpgsqlBatchCommand()

Initializes a new NpgsqlBatchCommand.

    public NpgsqlBatchCommand()

### NpgsqlBatchCommand(string)

Initializes a new NpgsqlBatchCommand.

    public NpgsqlBatchCommand(string commandText)

#### Parameters

`commandText` string

  The text of the NpgsqlBatchCommand.

## Properties

### AppendErrorBarrier

Appends an error barrier after this batch command. Defaults to the value of EnableErrorBarriers on the batch.

    public bool? AppendErrorBarrier { get; set; }

#### Property Value

bool?

#### Remarks

By default, any exception in a command causes later commands in the batch to be skipped, and earlier commands to be rolled back. Appending an error barrier ensures that errors from this command (or previous ones) won't cause later commands to be skipped, and that errors from later commands won't cause this command (or previous ones) to be rolled back).

Note that if the batch is executed within an explicit transaction, the first error places the transaction in a failed state, causing all later commands to fail in any case. As a result, this option is useful mainly when there is no explicit transaction.

At the PostgreSQL wire protocol level, this corresponds to inserting a Sync message after this command, rather than grouping all the batch's commands behind a single terminating Sync.

Controlling error barriers on a command-by-command basis is an advanced feature, consider enabling error barriers for the entire batch via EnableErrorBarriers.

### CanCreateParameter

    public override bool CanCreateParameter { get; }

#### Property Value

bool

### CommandText

Gets or sets the text command to run against the data source.

    public override string CommandText { get; set; }

#### Property Value

string

  The text command to execute. The default value is an empty string ("").

### CommandType

Gets or sets how the CommandText property is interpreted.

    public override CommandType CommandType { get; set; }

#### Property Value

CommandType

  One of the enumeration values that specifies how a command string is interpreted. The default is `Text`.

### DbParameterCollection

Gets the collection of DbParameter objects.

    protected override DbParameterCollection DbParameterCollection { get; }

#### Property Value

DbParameterCollection

  The parameters of the SQL statement or stored procedure.

### OID

For an INSERT, the object ID of the inserted row if RecordsAffected is 1 and the target table has OIDs; otherwise 0.

    public uint OID { get; }

#### Property Value

uint

### Parameters

Gets the collection of DbParameter objects. For more information on parameters, see Configuring Parameters and Parameter Data Types.

    public NpgsqlParameterCollection Parameters { get; }

#### Property Value

NpgsqlParameterCollection

  The parameters of the SQL statement or stored procedure.

### RecordsAffected

Gets the number of rows changed, inserted, or deleted by execution of this specific DbBatchCommand.

    public override int RecordsAffected { get; }

#### Property Value

int

  The number of rows changed, inserted, or deleted. -1 for SELECT statements; 0 if no rows were affected or the statement failed.

### Rows

The number of rows affected or retrieved.

    public ulong Rows { get; }

#### Property Value

ulong

#### Remarks

See the command tag in the CommandComplete message for the meaning of this value for each StatementType, https://www.postgresql.org/docs/current/static/protocol-message-formats.html

### StatementType

Specifies the type of query, e.g. SELECT.

    public StatementType StatementType { get; }

#### Property Value

StatementType

## Methods

### CreateParameter()

    public override NpgsqlParameter CreateParameter()

#### Returns

NpgsqlParameter

### ToString()

Returns the CommandText.

    public override string ToString()

#### Returns

string