2

This is my code:

byte[] imgg = (byte[])(myReader["StudPic"]);
                    if (imgg == null)
                    {
                        pictureBox11.Image = defaultpic;
                    }
                    else
                    {
                        MemoryStream mstream = new MemoryStream(imgg);
                        pictureBox11.Image = Image.FromStream(mstream);
                    }

I got this error: unable to cast object of type system.dbnull to type system.byte[]
Data type is Blob. But if it has a value, it works fine, it fetches the image.

1 Answers1

0

you can add a condition to check weather it has value or not

if(myReader["StudPic"] != System.DBNull.Value))
{
  byte[] imgg = (byte[])(myReader["StudPic"]);
  pictureBox11.Image = defaultpic;
}
Usman
  • 4,615
  • 2
  • 17
  • 33