title: Error: Procedure or function expects parameter which was not supplied
body: <p>Currently, my program in Visual Studio dynamically adds my data from my Repeater into my database.</p>
  
  <p>Now I need to add the ID, my EventId and FormId, which I collected manually outside of the Repeater.</p>
  
  <p>I need to add this in:</p>
  
  <pre><code> sqlCmd.Parameters.Add("@EventId", SqlDbType.Int).Value = eventId;
   sqlCmd.Parameters.Add("@FormId", SqlDbType.Int).Value = formId;
  </code></pre>
  
  <p>However with how my code is setup, it gives an error when I add this code that says:</p>
  
  <blockquote>
    <p>Additional information: Procedure or function 'spInsFormRegistrant'
    expects parameter '@EventId', which was not supplied.</p>
  </blockquote>
  
  <p>Working code (with error code commented out):</p>
  
  <pre><code> protected void BtnSubmit_Click(object sender, EventArgs e)
   {
              using (SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["Events2"].ConnectionString))
              {
                  sqlConn.Open();
  
                  using (SqlCommand sqlCmd = new SqlCommand())
                  {
  
                     //sqlCmd.Parameters.Add("@EventId", SqlDbType.Int).Value = eventId;
                     //sqlCmd.Parameters.Add("@FormId", SqlDbType.Int).Value = formId;
                      foreach (RepeaterItem rpItem in RepeaterForm.Items)
                      {
                          Label lblDisplayName = rpItem.FindControl("lblDisplayName") as Label;
                          Label lblColumnName = rpItem.FindControl("lblColumnName") as Label;
                          TextBox txtColumnValue = rpItem.FindControl("txtColumnValue") as TextBox;
  
                          if (txtColumnValue != null)
                          {
                              sqlCmd.Connection = sqlConn;
                              sqlCmd.CommandType = CommandType.StoredProcedure;
                              sqlCmd.CommandText = "spInsFormRegistrant";
                              sqlCmd.Parameters.Clear();
  
                              sqlCmd.Parameters.Add("@ColumnName", SqlDbType.NVarChar).Value = lblColumnName.Text;
                              sqlCmd.Parameters.Add("@ColumnValue", SqlDbType.NVarChar).Value = txtColumnValue.Text;
  
                          sqlCmd.ExecuteNonQuery();
                          }
                      }
                  }
              }
              PnlNone.Visible = false;
              PnlExist.Visible = false;
              PnlSuccess.Visible = true;
              PnlFail.Visible = false;
          }
  </code></pre>
  
  <p>So I just need to know where to add in <code>@EventId</code> and <code>@FormId</code> for this to function correctly. Each time I try it, it does not work. I must be missing something small for this to not produce an error. Or maybe it is an issue with my stored procedure...?</p>
  
  <p>Stored Procedure</p>
  
  <pre><code>ALTER PROCEDURE [dbo].[spInsFormRegistrant]
      -- Add the parameters for the stored procedure here
       @EventId int,
       @FormId int,
       @ColumnName varchar(100),
      @ColumnValue varchar(100)
  AS
  BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;
  
      -- Insert statements for procedure here
       declare @Query nvarchar(4000)
      declare @ParmDefinition nvarchar(500);
  
      set @Query = 'INSERT into Registrant(DateCreated,EventId,FormId,'+ (@ColumnName) +') values (CURRENT_TIMESTAMP, @EventId, @FormId, @ColumnValue)'
      set @ParmDefinition = N'@ColumnValue varchar(100)'
      exec sp_executesql @Query, @ParmDefinition, @ColumnValue = @ColumnValue
  
  END
  </code></pre>