I have the following C# code:
sqlCommand.Parameters.AddWithValue("@Parameter", table.Value ?? DBNull.Value);
But it throws the following compilation error:
Operator
??
cannot be applied to operands of typestring
andSystem.DBNull
Why doesn't the compiler allow this syntax?
Both operands need to be object. Use explicit cast:
(object)table.Value ?? DBNull.Value;