title: Convert an int to a string saved in a SQL Server database
body: <p>I have a SQL Server database with a table <code>Event_Tab</code> with an <code>Int</code> column <code>Code</code>. I want to associate this <code>Code</code> with a specific <code>string</code> and this so I don't save string variable in my table. </p>
  
  <p>So, I wrote a procedure <code>GetStringCode</code> with In16 input parameter and it returns the string that I need, then I fill it in a listview with the other parameter saved in my table   </p>
  
  <p>This is my code to do it :</p>
  
  <pre><code>using (SqlConnection connection = new SqlConnection(connectionstring))
  using (SqlDataAdapter adapter = new SqlDataAdapter(query, connection))
  {
      DataTable table = new DataTable();
      adapter.Fill(table);
  
      foreach(DataRow dr in table.Rows)
      {
          ListViewItem items = new ListViewItem(dr["Machine"].ToString());                    
          items.SubItems.Add(GetStringCode((short)dr["Code"]).ToString());
          items.SubItems.Add(dr["Date_time"].ToString());
          listview.Items.Add(items);
      }
  }  
  </code></pre>
  
  <p>If you notice, I did a cast to get rid of an error </p>
  
  <blockquote>
    <p>Cannot convert from object to short</p>
  </blockquote>
  
  <p>and so far everything seems okay. But when a try to run this code, I am getting an error </p>
  
  <blockquote>
    <p>The specific cast is invalid</p>
  </blockquote>
  
  <p>What is the problem because I can't seem to find it...</p>