When I retrieve any Scalar value from the database, I usually write code like this for nullable fields.
cmd.ExecuteScalar() == DBNull.Value ? 0 : (int)cmd.ExecuteScalar()
But I don't like it because it executes the Executescalar statement twice. It's an extra trip to the server for my website and in favor of performance I don't want to do this.
Is there any way I can get rid of this extra ExecuteScalar()?