Having an issue with casting a datetime from a reader where the value is null.

form._date101 = reader[52] == DBNull.Value ? DBNull.Value : (DateTime?)reader[52];

getting: Type of conditional expression cannot be determined because there is no implicit conversion between 'System.DBNull' and 'System.DateTime?'

any ideas?

You can also take Jon's answer and add it as an extension method like this:

public static class ReaderExtensions
{
    public static DateTime? GetNullableDateTime(this SqlDataReader reader, string name) =>
        reader[name] == DBNull.Value ? (DateTime?)null : (DateTime?)reader[name];
}

Then you can use it like this:

item.PatientDob = reader.GetNullableDateTime("Birth_Dt");