Search code examples
c#dbnull

How to handle System.DBNull?


I have a object with type:

dynamic {System.DBNull}

I want to check it:

if (myObject!= null || myObject!= DBNull.Value)
{
   MessageBox.Show("Oh hi");
}

But the MessageBox always appears. Whats wrong, is it another type?


Solution

  • This expression is always true

    myObject != null || myObject != DBNull.Value
    

    because myObject cannot be null and DBNull.Value at the same time. Replace || with && to fix.