>Hi everybody,
>
>I am getting this error
>
>"Object cannot be cast from DBNull to other types"
>
>on this piece of code:
>
>start_time = Convert.ToDateTime((row["start_time"] ?? DTSqlMinDate));
>
>As you see here, I attempt to use C# coalesce operator in order to avoid this error, but it doesn't work. How should I correct this error without introducing extra nullable datetime variable?
>
>Thanks in advance.
>
>UPDATE. This seems to fix the problem
>
>Convert.ToDateTime((row["start_time"]== DBNull.Value)?DTSqlMinDate:row["start_time"]);
I think you were confusing DBNull with C# null which is what the ?? operator uses.......