title: How to create dynamic parameters in SQL Server stored procedure
body: <p>I have a form that generate inputs dynamically, then I get their values and generate command parameters dynamically.</p>
  
  <pre><code>    SqlConnection con = new SqlConnection(cs);
  
      SqlCommand cmd =new SqlCommand("insert_op",con);
      cmd.CommandType = CommandType.StoredProcedure;
  
      for (int i = 0; i &lt; Request.Form.Count; i++)
      {
          if (Request.Form["frm_option" + (i + 1)] != null)
          {
  
              cmd.Parameters.AddWithValue("@op" + i, Request.Form["frm_option" + (i + 1)]);
          }
      }
      try
      {
          using (con)
          {
              con.Open();
              cmd.ExecuteNonQuery();
          }
      }
      catch
      {
      }
  </code></pre>
  
  <p>How can I pass these dynamic parameters to SQL Server stored procedure and how should stored procedure be?</p>