I assume that imageBytes
is an array of bytes (byte[]
). As your code compiles, the Photo
property must be of type byte
. You try to convert the byte array to a single byte in this line:
objUser.Photo = Convert.ToByte( imagebytes);
This leads to an exception as the byte array does not implement IConvertible
which would be required in order for the conversion to work. But how would you want to convert a byte array to a single byte anyway? How should the conversion mechanism know which byte of the array to assign to the single byte? Therefore I suspect that you'd rather want the Photo
property to also be of type byte[]
so that it is able to store the complete picture and not only one byte of it.
So in order to fix this, try to change the property in your Entity to byte[]
(which might also involve changing the database schema) and assign the array directly without using Convert.ToByte()
.