Ejemplo n.º 1
0
        /// <summary>
        /// Adds a parameter to a command that can accept a list of IDs.
        /// </summary>
        /// <param name="command">The command object to update.</param>
        /// <param name="name">A string containing the name of the parameter.</param>
        /// <param name="stringList">The string list.</param>
        /// <returns></returns>
        public static IDbDataParameter AddStringListParameter(this IDbCommand command, string name, IEnumerable <string> stringList)
        {
            /////
            // Define data table
            /////
            DataTable dataTable = command.CreateTableValuedParameter(TableValuedParameterType.NVarCharMaxListType);

            /////
            // Fill table
            /////
            foreach (string value in stringList)
            {
                dataTable.Rows.Add(value);
            }

            return(command.AddTableValuedParameter(name, dataTable));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds a parameter to a command that can accept a list of some arbitrary object type.
        /// </summary>
        /// <param name="command">The command object to update.</param>
        /// <param name="name">A string containing the name of the parameter.</param>
        /// <param name="listType">The type of data.</param>
        /// <param name="dataList">The data list.</param>
        /// <returns></returns>
        public static IDbDataParameter AddListParameter(this IDbCommand command, string name, TableValuedParameterType listType, IEnumerable <object> dataList)
        {
            /////
            // Define data table
            /////
            DataTable dataTable = command.CreateTableValuedParameter(listType);

            /////
            // Fill table
            /////
            foreach (object value in dataList)
            {
                dataTable.Rows.Add(value);
            }

            return(command.AddTableValuedParameter(name, dataTable));
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Adds a parameter to a command that can accept a list of IDs.
        /// </summary>
        /// <param name="command">
        ///     The command object to update.
        /// </param>
        /// <param name="name">
        ///     A string containing the name of the parameter.
        /// </param>
        /// <param name="idList">
        ///     The list of IDs, which must be unique.
        /// </param>
        public static IDbDataParameter AddIdListParameter(this IDbCommand command, string name, IEnumerable <long> idList)
        {
            /////
            // Define data table
            /////
            DataTable dataTable = command.CreateTableValuedParameter(TableValuedParameterType.BigInt);

            /////
            // Fill table
            /////
            foreach (long id in idList.Distinct( ))
            {
                dataTable.Rows.Add(id);
            }

            return(command.AddTableValuedParameter(name, dataTable));
        }