I am trying to pass null value to image database field if the ImageByteArray is not provided to Parameters.Add as shown here
cmd.Parameters.Add(new SqlParameter("@Img", SqlDbType.Image)).Value =
DBNull.Value ? null : ImageByteArray;
but I am getting error that says
Cannot implicitly convert type 'System.DBNull' to 'bool'
first is that correct way to do it >
if yes the how to pass null value if the ImageByteArray is not provided ?
i do not know if am right what i want to do is passing null to the parameter if the Byte Array is not provided so I avoid the Procedure or function expects parameter '@img', which was not supplied.
someCondition ? value1 : value2.DBNull.Valueto the ternary operator. That only accepts a boolean and DBNull.Value cannot be implicitly converted to a boolean.ImageByteArray ?? DBNull.Valueinstead?Procedure or function expects parameter '@img', which was not supplied.ImageByteArraydeclared? How is it passed in? If it's abyte[]can it really be null? Or just zero length?