title: Passing multiple SqlParameter to method
body: <p>In my main form, I have implemented this code..</p>
  
  <pre><code>void SampleMethod(string name, string lastName, string database)
  {
          SqlParameter sqlParam = new SqlParameter();
          sqlParam.ParameterName = "@name";
          sqlParam.Value = name;
          sqlParam.SqlDbType = SqlDbType.NVarChar;
  
          SqlParameter sqlParam1 = new SqlParameter();
          sqlParam1.ParameterName = "@lastName";
          sqlParam1.Value = lastName;
          sqlParam1.SqlDbType = SqlDbType.NVarChar;
  
          SqlParameter sqlParam2 = new SqlParameter();
          sqlParam2.ParameterName = "@database";
          sqlParam2.Value = database;
          sqlParam2.SqlDbType = SqlDbType.NVarChar;
  
          SampleClass sampleClass = new SampleClass(new DBConn(@serverName, tableName, userName, password));
          sampleClass.executeStoredProc(dataGridView1, "sp_sampleStoredProc", sqlParam, sqlParam1, sqlParam2);
  }
  </code></pre>
  
  <p>And in my <code>SampleClass</code>, I have this kind of method.</p>
  
  <pre><code>public DataGridView executeStoredProc(DataGridView dtgrdView, string storedProcName, params SqlParameter[] parameters)
  {
          try
          {
              DataTable dt = new DataTable();
              sqlDA = new SqlDataAdapter(storedProcName, sqlconn);
              sqlDA.SelectCommand.CommandType = CommandType.StoredProcedure;
              sqlDA.SelectCommand.CommandTimeout = 60;
  
              // Loop through passed parameters
              if (parameters != null &amp;&amp; parameters.Length &gt; 0)
              {
                  foreach (var p in parameters)
                      sqlDA.SelectCommand.Parameters.Add(p);
              }
  
              sqlDA.Fill(dt);
              dtgrdView.DataSource = dt;
              sqlconn.Close();
          }
          catch (Exception ex)
          {
              MessageBox.Show(ex.Message);
              sqlconn.Close();
          }
  
          return dtgrdView;
  }
  </code></pre>
  
  <p>What I am trying to do is avoid multiple </p>
  
  <pre><code>SqlParameter sqlParam = new SqlParameter() 
  </code></pre>
  
  <p>in my code, I have tried so many solutions for this problem but I didn't get the right answer. I have also tried to research about this but I still couldn't get the right answer.</p>
  
  <p>Please don't mind my naming convention and other codes as I intentionally change many of them :) Thanks.</p>