# Class NpgsqlParameter

Namespace
  Npgsql

Assembly
  Npgsql.dll

This class represents a parameter to a command that will be sent to server

    public class NpgsqlParameter : DbParameter, IDbDataParameter, IDataParameter, ICloneable

Inheritance
  object
  MarshalByRefObject
  DbParameter
  NpgsqlParameter

Implements
  IDbDataParameter
  IDataParameter
  ICloneable

Derived
  NpgsqlParameter<T>

Inherited Members
  MarshalByRefObject.GetLifetimeService()
  MarshalByRefObject.InitializeLifetimeService()
  MarshalByRefObject.MemberwiseClone(bool)
  object.Equals(object)
  object.Equals(object, object)
  object.GetHashCode()
  object.GetType()
  object.MemberwiseClone()
  object.ReferenceEquals(object, object)
  object.ToString()

## Constructors

### NpgsqlParameter()

Initializes a new instance of the NpgsqlParameter class.

    public NpgsqlParameter()

### NpgsqlParameter(string?, NpgsqlDbType)

Initializes a new instance of the NpgsqlParameter class with the parameter name and the data type.

    public NpgsqlParameter(string? parameterName, NpgsqlDbType parameterType)

#### Parameters

`parameterName` string

  The name of the parameter to map.

`parameterType` NpgsqlDbType

  One of the NpgsqlDbType values.

### NpgsqlParameter(string?, NpgsqlDbType, int)

Initializes a new instance of the NpgsqlParameter.

    public NpgsqlParameter(string? parameterName, NpgsqlDbType parameterType, int size)

#### Parameters

`parameterName` string

  The name of the parameter to map.

`parameterType` NpgsqlDbType

  One of the NpgsqlDbType values.

`size` int

  The length of the parameter.

### NpgsqlParameter(string?, NpgsqlDbType, int, string?)

Initializes a new instance of the NpgsqlParameter

    public NpgsqlParameter(string? parameterName, NpgsqlDbType parameterType, int size, string? sourceColumn)

#### Parameters

`parameterName` string

  The name of the parameter to map.

`parameterType` NpgsqlDbType

  One of the NpgsqlDbType values.

`size` int

  The length of the parameter.

`sourceColumn` string

  The name of the source column.

### NpgsqlParameter(string, NpgsqlDbType, int, string?, ParameterDirection, bool, byte, byte, DataRowVersion, object)

Initializes a new instance of the NpgsqlParameter.

    public NpgsqlParameter(string parameterName, NpgsqlDbType parameterType, int size, string? sourceColumn, ParameterDirection direction, bool isNullable, byte precision, byte scale, DataRowVersion sourceVersion, object value)

#### Parameters

`parameterName` string

  The name of the parameter to map.

`parameterType` NpgsqlDbType

  One of the NpgsqlDbType values.

`size` int

  The length of the parameter.

`sourceColumn` string

  The name of the source column.

`direction` ParameterDirection

  One of the ParameterDirection values.

`isNullable` bool

  true if the value of the field can be null, otherwise false.

`precision` byte

  The total number of digits to the left and right of the decimal point to which Value is resolved.

`scale` byte

  The total number of decimal places to which Value is resolved.

`sourceVersion` DataRowVersion

  One of the DataRowVersion values.

`value` object

  An object that is the value of the NpgsqlParameter.

### NpgsqlParameter(string?, DbType)

Initializes a new instance of the NpgsqlParameter.

    public NpgsqlParameter(string? parameterName, DbType parameterType)

#### Parameters

`parameterName` string

  The name of the parameter to map.

`parameterType` DbType

  One of the DbType values.

### NpgsqlParameter(string?, DbType, int)

Initializes a new instance of the NpgsqlParameter.

    public NpgsqlParameter(string? parameterName, DbType parameterType, int size)

#### Parameters

`parameterName` string

  The name of the parameter to map.

`parameterType` DbType

  One of the DbType values.

`size` int

  The length of the parameter.

### NpgsqlParameter(string?, DbType, int, string?)

Initializes a new instance of the NpgsqlParameter.

    public NpgsqlParameter(string? parameterName, DbType parameterType, int size, string? sourceColumn)

#### Parameters

`parameterName` string

  The name of the parameter to map.

`parameterType` DbType

  One of the DbType values.

`size` int

  The length of the parameter.

`sourceColumn` string

  The name of the source column.

### NpgsqlParameter(string, DbType, int, string?, ParameterDirection, bool, byte, byte, DataRowVersion, object)

Initializes a new instance of the NpgsqlParameter.

    public NpgsqlParameter(string parameterName, DbType parameterType, int size, string? sourceColumn, ParameterDirection direction, bool isNullable, byte precision, byte scale, DataRowVersion sourceVersion, object value)

#### Parameters

`parameterName` string

  The name of the parameter to map.

`parameterType` DbType

  One of the DbType values.

`size` int

  The length of the parameter.

`sourceColumn` string

  The name of the source column.

`direction` ParameterDirection

  One of the ParameterDirection values.

`isNullable` bool

  true if the value of the field can be null, otherwise false.

`precision` byte

  The total number of digits to the left and right of the decimal point to which Value is resolved.

`scale` byte

  The total number of decimal places to which Value is resolved.

`sourceVersion` DataRowVersion

  One of the DataRowVersion values.

`value` object

  An object that is the value of the NpgsqlParameter.

### NpgsqlParameter(string?, object?)

Initializes a new instance of the NpgsqlParameter class with the parameter name and a value.

    public NpgsqlParameter(string? parameterName, object? value)

#### Parameters

`parameterName` string

  The name of the parameter to map.

`value` object

  The value of the NpgsqlParameter.

#### Remarks

When you specify an object in the value parameter, the DbType is inferred from the CLR type.

When using this constructor, you must be aware of a possible misuse of the constructor which takes a DbType parameter. This happens when calling this constructor passing an int 0 and the compiler thinks you are passing a value of DbType. Use ToInt32(object) for example to have compiler calling the correct constructor.

## Properties

### Collection

The collection to which this parameter belongs, if any.

    public NpgsqlParameterCollection? Collection { get; set; }

#### Property Value

NpgsqlParameterCollection

### DataTypeName

Used to specify which PostgreSQL type will be sent to the database for this parameter.

    public string? DataTypeName { get; set; }

#### Property Value

string

### DbType

Gets or sets the DbType of the parameter.

    public override sealed DbType DbType { get; set; }

#### Property Value

DbType

  One of the DbType values. The default is object.

### Direction

Gets or sets a value that indicates whether the parameter is input-only, output-only, bidirectional, or a stored procedure return value parameter.

    public override sealed ParameterDirection Direction { get; set; }

#### Property Value

ParameterDirection

  One of the ParameterDirection values. The default is `Input`.

#### Exceptions

ArgumentException

  The property is not set to one of the valid ParameterDirection values.

### IsNullable

Gets or sets a value that indicates whether the parameter accepts null values.

    public override sealed bool IsNullable { get; set; }

#### Property Value

bool

  true if null values are accepted; otherwise false. The default is false.

### NpgsqlDbType

Gets or sets the NpgsqlDbType of the parameter.

    [DbProviderSpecificTypeProperty(true)]
    public NpgsqlDbType NpgsqlDbType { get; set; }

#### Property Value

NpgsqlDbType

  One of the NpgsqlDbType values. The default is NpgsqlDbType.

### NpgsqlValue

Gets or sets the value of the parameter.

    [TypeConverter(typeof(StringConverter))]
    public object? NpgsqlValue { get; set; }

#### Property Value

object

  An object that is the value of the parameter. The default value is null.

### ParameterName

Gets or sets The name of the NpgsqlParameter.

    public override sealed string ParameterName { get; set; }

#### Property Value

string

  The name of the NpgsqlParameter. The default is an empty string.

### PostgresType

The PostgreSQL data type, such as int4 or text, as discovered from pg_type. This property is automatically set if parameters have been derived via DeriveParameters(NpgsqlCommand) and can be used to acquire additional information about the parameters' data type.

    public PostgresType? PostgresType { get; }

#### Property Value

PostgresType

### Precision

Gets or sets the maximum number of digits used to represent the Value property.

    public byte Precision { get; set; }

#### Property Value

byte

  The maximum number of digits used to represent the Value property. The default value is 0, which indicates that the data provider sets the precision for Value.

### Scale

Gets or sets the number of decimal places to which Value is resolved.

    public byte Scale { get; set; }

#### Property Value

byte

  The number of decimal places to which Value is resolved. The default is 0.

### Size

Gets or sets the maximum size, in bytes, of the data within the column.

    public override sealed int Size { get; set; }

#### Property Value

int

  The maximum size, in bytes, of the data within the column. The default value is inferred from the parameter value.

### SourceColumn

Gets or sets the name of the source column mapped to the DataSet and used for loading or returning the Value.

    public override sealed string SourceColumn { get; set; }

#### Property Value

string

  The name of the source column mapped to the DataSet. The default is an empty string.

### SourceColumnNullMapping

Gets or sets a value which indicates whether the source column is nullable. This allows DbCommandBuilder to correctly generate Update statements for nullable columns.

    public override sealed bool SourceColumnNullMapping { get; set; }

#### Property Value

bool

  true if the source column is nullable; false if it is not.

### SourceVersion

Gets or sets the DataRowVersion to use when you load Value.

    public override sealed DataRowVersion SourceVersion { get; set; }

#### Property Value

DataRowVersion

  One of the DataRowVersion values. The default is `Current`.

#### Exceptions

ArgumentException

  The property is not set to one of the DataRowVersion values.

### Value

Gets or sets the value of the parameter.

    [TypeConverter(typeof(StringConverter))]
    public override object? Value { get; set; }

#### Property Value

object

  An object that is the value of the parameter. The default value is null.

## Methods

### Clone()

Creates a new NpgsqlParameter that is a copy of the current instance.

    public NpgsqlParameter Clone()

#### Returns

NpgsqlParameter

  A new NpgsqlParameter that is a copy of this instance.

### ResetDbType()

Resets the DbType property to its original settings.

    public override void ResetDbType()