title: How to add a number to a Sqlcommand.Parameters?
body: <p>Here's my method:</p>
  
  <pre><code>public void EjecutarGuardar(string ProcedimientoAlmacenado, object[] Parametros)
          {
              SqlConnection Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
  
              SqlCommand Command = Connection.CreateCommand();
              Command.CommandText = ProcedimientoAlmacenado;
              Command.CommandType = CommandType.StoredProcedure;
              foreach (object X in Parametros)
              {
                  Command.Parameters.Add(X);
              }            
  
              Connection.Open();
              Command.ExecuteNonQuery();
              Connection.Close();
  
              Connection.Dispose();
          }
  </code></pre>
  
  <p>Say I added an int to my object array PARAMETROS, when it reaches the foreach statement I get an error:</p>
  
  <blockquote>
    <p>The SqlParameterCollection only
    accepts non-null SqlParameter type
    objects, not Int32 objects.</p>
  </blockquote>
  
  <p>So, how can I load all of my parameters outside of this class, and then place them all into a generic array, and pass it on to this method to do it's magic. Any help?</p>
  
  <p>Edit: A friend sent me this code, would it work? I cant understand what it's doing. :S</p>
  
  <pre><code>protected void CargarParametros(SqlCommand Com, System.Object[] Args)
          {                
              for (int i = 1; i &lt; Com.Parameters.Count; i++)
              {
                  SqlParameter P = (SqlParameter)Com.Parameters[i];
                  if (i &lt;= Args.Length )
                      P.Value = Args[i - 1];
                  else
                      P.Value = null;
              }
          }
  </code></pre>