title: How to convert an string to a Char(20) sql datatype
body: <p>I am trying to insert a string into a <code>char(20)</code> column in my SQL Server database.</p>
  
  <p>I set the string to be equal to a value and then add it to a parameter</p>
  
  <pre><code>thisstring = "1914"
  cmd.Parameters.AddWithValue("@code", thisstring)
  </code></pre>
  
  <p>However every time I try it ends up looking like this in the database</p>
  
  <p><img src="https://i.stack.imgur.com/IDm5D.png" alt="picture"></p>
  
  <p>I need it to look like the <code>1913, 000000, 000001</code> ones.</p>
  
  <p>When I try to pad the string with spaces </p>
  
  <pre><code>thisstring= thisstring.PadLeft(20, " ")
  </code></pre>
  
  <p>or</p>
  
  <pre><code>thisstring = "     " &amp; thisstring
  </code></pre>
  
  <p>I am getting </p>
  
  <blockquote>
    <p>String or binary data would be truncated</p>
  </blockquote>
  
  <p>even if the field wasn't 20 characters total</p>
  
  <p>What am I doing wrong?</p>
  
  <p>Edit*** here is the column in SQL Server</p>
  
  <p><a href="https://imgur.com/BbV6VQv" rel="nofollow noreferrer">http://imgur.com/BbV6VQv</a></p>