title: Conversion error from database smallint into C# nullable int
body: <p>I have a security_role_cd column in database of <code>smallint</code> datatype. I am selecting this column using following code into a <code>nullable int</code> variable. </p>
  
  <p>I am getting following error: </p>
  
  <blockquote>
    <p>Error     3       Type of conditional expression cannot be determined because there is no implicit conversion between 'null' and 'short'        </p>
  </blockquote>
  
  <p>What is the correct code to overcome this error?</p>
  
  <pre><code>SELECT R.security_role_cd  FROM Security_Role R WHERE security_role_name = 'Admin'
  </code></pre>
  
  <p>C# </p>
  
  <pre><code>        int? roleID = null;
          string commandText = "SELECT R.security_role_cd  FROM Security_Role R WHERE security_role_name = @roleName";
          SqlCommand command = new SqlCommand(commandText, connection);
          command.CommandType = System.Data.CommandType.Text;
          command.Parameters.AddWithValue("@roleName",roleName);
          SqlDataReader readerRole = command.ExecuteReader();
          if (readerRole.HasRows)
          {
              while (readerRole.Read())
              {
                  roleID = readerRole.GetInt16(0) == 0 ? null : readerRole.GetInt16(0) ;
  
              }
          }
          readerRole.Close();
  </code></pre>