/// <summary>
        /// Adds the parameter to the command..
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="name">The name.</param>
        /// <param name="value">The value.</param>
        /// <returns>The data command.</returns>
        /// <exception cref="ArgumentNullException">command.</exception>
        public static IDataCommand AddParameter(this IDataCommand command,
                                                string name,
                                                object value)
        {
            if (command is null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            var p = command.CreateParameter();

            p.ParameterName = name;
            p.Value         = value;

            command.Add(p);
            return(command);
        }
示例#2
0
 /// <summary>
 /// 赋sql语句参数值
 /// </summary>
 /// <param name="cmd"></param>
 /// <param name="paras"></param>
 public static void PrepareCommand(IDataCommand cmd, Hashtable paras)
 {
     IDbDataParameter para = null;
     if (paras != null)
     {
         foreach (DictionaryEntry de in paras)
         {
             para = cmd.CreateParameter();
             para.ParameterName = de.Key.ToString();
             para.Value = de.Value.ToString();
             cmd.AddParameter(para);
         }
     }
 }