title: How can I add members to an array of SqlParameter?
body: <p>I've got this code:</p>
  
  <pre><code>private SqlParameter[] GetSPParams()
  {
      SqlParameter[] spParams = null;
      int loopNum = 1;
      while (ParamExists(loopNum))
      {
          //spParams.
          new SqlParameter()
          {
              ParameterName = GetParamName(loopNum),
              SqlDbType = GetSqlDbType(loopNum),
              Value = GetParamValue(loopNum)
          };
          loopNum++;
      }
      return spParams;
  }
  </code></pre>
  
  <p>...which, as you can see, returns null always.</p>
  
  <p>The "spParams." is commented out because I found no "Add" or such among the Intellisense possibilities - or anything that looked right.</p>
  
  <p>I need a SqlParameter array, because that is what ends up getting passed to my method that runs the Stored Proc:</p>
  
  <pre><code>private void RunStoredProc()
  {
      SqlParameter[] spparams = GetSPParams();
      DataTable dtSPResults = SPRunnerSQL.ExecuteSQLReturnDataTable(comboBoxCPSStoredProcs.Text,
          CommandType.StoredProcedure,
          spparams
      );
      rowsReturned = dtSPResults.Rows.Count;
      labelRowsReturned.Text = String.Format("Rows returned: {0}", rowsReturned);
      if (rowsReturned &gt; 0)
      {
          dataGridView.DataSource = dtSPResults;
      }
  }
  
  . . .
  
  public static DataTable ExecuteSQLReturnDataTable(string sql, CommandType cmdType, params SqlParameter[] parameters)
  </code></pre>
  
  <p>So how can I add SqlParameter values to the SqlParameter array?</p>