データ型のデータベースに security_role_cd 列がありますsmallint。次のコードをnullable int変数に使用して、この列を選択しています。
次のエラーが表示されます:
エラー 3 'null' と 'short' の間に暗黙的な変換がないため、条件式の型を特定できません
このエラーを克服するための正しいコードは何ですか?
SELECT R.security_role_cd  FROM Security_Role R WHERE security_role_name = 'Admin'
C#
        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();