Npgsql.NpgsqlParameterCollection.AddWithValue C# (CSharp) Method

AddWithValue() public method

Adds a NpgsqlParameter to the NpgsqlParameterCollection given the specified parameter name and value.
public AddWithValue ( string parameterName, NpgsqlDbType parameterType, int size, object value ) : Npgsql.NpgsqlParameter
parameterName string The name of the NpgsqlParameter.
parameterType NpgsqlDbType One of the NpgsqlDbType values.
size int The length of the column.
value object The Value of the NpgsqlParameter to add to the collection.
return Npgsql.NpgsqlParameter
        public NpgsqlParameter AddWithValue(string parameterName, NpgsqlDbType parameterType, int size, object value)
        {
            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "AddWithValue", parameterName, parameterType, size, value);

            NpgsqlParameter param = new NpgsqlParameter(parameterName, parameterType, size);

            param.Value = value;

            return this.Add(param);
        }

Same methods

NpgsqlParameterCollection::AddWithValue ( string parameterName, NpgsqlDbType parameterType, int size, string sourceColumn, object value ) : Npgsql.NpgsqlParameter
NpgsqlParameterCollection::AddWithValue ( string parameterName, NpgsqlDbType parameterType, object value ) : Npgsql.NpgsqlParameter
NpgsqlParameterCollection::AddWithValue ( string parameterName, object value ) : Npgsql.NpgsqlParameter

Usage Example

        /// <summary>
        /// Add range with value
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="values"></param>
        public static void AddRangeWithValue(this NpgsqlParameterCollection conn, Dictionary <string, object> values)
        {
            conn.CheckNull(nameof(conn));
#if NETFRAMEWORK || NETSTANDARD2_0
            foreach (var pair in values)
            {
                var key   = pair.Key;
                var value = pair.Value;
#else
            foreach (var(key, value) in values)
            {
#endif
                conn.AddWithValue(key, value);
            }
        }
    }