Probably the query returns null. Try this:
bool? ev = (bool?)command.ExecuteScalar();
if(ev.GetValueOrDefault(false))
{
MessageBox.Show(...);
}
The ?
means nullable, so it this way the value returned from the query is allowed to be null
.