Table of Contents

Method AddParamIf

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

AddParamIf(bool, string, DbType, ParameterDirection)

Conditionally adds a parameter of a DbType with no value.

public ExpressiveSqlCommand AddParamIf(bool condition, string name, DbType type, ParameterDirection direction)

Parameters

condition bool

true to add the parameter; otherwise, false.

name string

The name of the parameter.

type DbType

The database type of the parameter.

direction ParameterDirection

The direction of the parameter. An input or input-output parameter with no value is sent as a NULL of that type.

Returns

ExpressiveSqlCommand

This instance for use in method chaining.

Remarks

A constant 0 with a direction (AddParam("@n", 0, ParameterDirection.InputOutput)) binds to this overload as a DbType: write (object)0 or use a variable.

Exceptions

ArgumentNullException

The parameter is added and name is null.

ArgumentException

The parameter is added and name is empty or white space, or SQL Server has no type for type.