title: C# SqlParameters Short Hand
body: <p>I'm taking data that is in a <code>List</code> of <code>Record</code> objects and putting their contents in to a database:</p>
  <pre><code>// Processes a Record and adds it to the database
  public bool addRecord(SqlConnection db, List&lt;Record&gt; recordsToAdd)
  {
      using (SqlCommand command = db.CreateCommand())
      {
          foreach (Record record in recordsToAdd)
          {
              // Set the query command text
              command.CommandText = @&quot;INSERT INTO SMDGROUP_STPRODMASTER (PRODCODE, TOTFREE, TOTPHYS, ITEMTYPE, PRODESC) VALUES ('@PRODCODE', '@TOTFREE', '@TOTPHYS', '@ITEMTYPE', '@PRODESC')&quot;;
  
              SqlParameter param1 = new SqlParameter(&quot;@CURSTAT&quot;, record.curstat);
              SqlParameter param2 = new SqlParameter(&quot;@ITEMDESC&quot;, record.itemdesc);
              SqlParameter param3 = new SqlParameter(&quot;@PRODCODE&quot;, record.prodcode);
              SqlParameter param4 = new SqlParameter(&quot;@TOTFREE&quot;, record.totfree);
              SqlParameter param5 = new SqlParameter(&quot;@TOTPHYS&quot;, record.totphys);
              SqlParameter param6 = new SqlParameter(&quot;@ITEMTYPE&quot;, record.itemtype);
              SqlParameter param7 = new SqlParameter(&quot;@PRODESC&quot;, record.proddesc);
  
              command.Parameters.Add(param1);
              command.Parameters.Add(param2);
              command.Parameters.Add(param3);
              command.Parameters.Add(param4);
              command.Parameters.Add(param5);
              command.Parameters.Add(param6);
              command.Parameters.Add(param7);
  
              // Execute the query
              command.ExecuteNonQuery();
          }
          return true;
      }
  }
  </code></pre>
  <p>Here's my Record class:</p>
  <pre><code>class Record
  {
      public string curstat { get; set; }
      public string itemtype { get; set; }
      public string itemdesc { get; set; }
      public string prodcode { get; set; }
      public string proddesc { get; set; }
      public string totfree { get; set; }
      public string totphys { get; set; }
  }
  </code></pre>
  <p>Just from looking at the code, I've got a feeling that there is a shorter way of achieving this.</p>
  <p>But secondly, I'm not even sure if I've done it correctly that the <code>@PARAMETER</code> values are being replaced.</p>
  <p>If I view the contents of <code>command</code>, it still shows the query string with the <code>@</code> parameters.</p>
  <p>Also, I'm getting this error on <code>command.ExecuteNonQuery()</code>:</p>
  <blockquote>
  <p>String or binary data would be truncated.</p>
  <p>The statement has been terminated.</p>
  </blockquote>
  <p>So, my questions are:</p>
  <ul>
  <li>Is there a shorter way to set and add multiple parameters to the query?</li>
  <li>What could be causing the error?</li>
  </ul>