title: How can a stored procedure, that is called in C#, correctly insert data without giving all optional parameters?
body: <p>I'm trying to insert data with a stored procedure into my SQL Server database, from a C# program using Dapper. When I try to do this, I do not get any error, but some data is unfortunately inserted into the wrong column.</p>
  
  <p>The database consists of a lot of tables and columns, hence the use of a stored procedure to insert data correctly. I have extensively tested the stored procedure in SQL Server itself and know for sure that the data is placed correctly when directly executing SQL code on the server.</p>
  
  <p>Here is the code calling the stored procedure, and a tiny part of the stored procedure script.</p>
  
  <pre><code>public void AddIndividual(string genus, string species, string collection)
  {
      using (IDbConnection connection = new SqlConnection(connectionString: Helper.CnnVal("Rapento.Properties.Settings.Database1ConnectionString")))
      {
          List&lt;Individual&gt; individual = new List&lt;Individual&gt;();
          individual.Add(new Individual { GivenGenusName = genus, GivenSpeciesName = species, GivenCollectionName = collection });
          connection.Execute("dbo.AddIndividual @GivenGenusName, @GivenSpeciesName, @GivenCollectionName", individual);
      }
  }
  
  
  CREATE PROCEDURE AddIndividual
      @GivenGenusName varchar(255) = null,
      @GivenSpeciesName varchar(255) = null,
      @GivenDeterminedBy varchar(255) = null,
      @GivenDeterminationDate varchar(255) = null,
      ....
      @GivenCollectionName varchar(255) = null,
  </code></pre>
  
  <p>In the database, I can see that <code>GenusName</code> and <code>SpeciesName</code> are inserted correctly, but <code>CollectionName</code> is inserted into the column <code>DeterminedBy</code>. This is not how it's written in the SQL script. It comes to my attention that <code>DeterminedBy</code> is the third parameter in the script, which makes me think that the parameters are not passed on based on the names I give them, but based on their position (the order I in which pass them).</p>
  
  <p>So my question is: How can I insert this parameter in the correct column without having to pass every single optional parameter in the procedure?</p>
  
  <p>I hope I gave you all the info you need. Thanks!</p>