Table of Contents

Method AddParameter

Namespace
Open.Database.Extensions
Assembly
Open.Database.Extensions.MSSqlClient.dll

AddParameter(SqlCommand, string, object?, SqlDbType, ParameterDirection)

Adds a typed parameter with the given name, value, and direction to the command.

public static SqlParameter AddParameter(this SqlCommand target, string name, object? value, SqlDbType type, ParameterDirection direction = ParameterDirection.Input)

Parameters

target SqlCommand

The command to add the parameter to.

name string

The name of the parameter.

value object

The value of the parameter. It is assigned as given: a null is not converted to Value, so pass Value to send a database null.

type SqlDbType

The SqlDbType of the parameter.

direction ParameterDirection

The direction of the parameter.

Returns

SqlParameter

The created parameter, which has already been added to the command's parameter collection.

Exceptions

ArgumentNullException

target or name is null.

ArgumentException

name is empty or white space.