Reputation: 5299
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?
Upvotes: 1
Views: 2330
Reputation: 19151
There is also a function for checking for DBNull:
if(myObject != null && !Convert.IsDBNull(myObject))
{
MessageBox.Show("Oh hi");
}
Upvotes: 2
Reputation: 13484
Try this code
if(myObject != DBNull.Value)
{
MessageBox.Show("Oh hi");
}
or
if(myObject != null && myObject != DBNull.Value)
{
MessageBox.Show("Oh hi");
}
Upvotes: 1
Reputation: 727137
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.
Upvotes: 5