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.

0

1 Answer 1

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;
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.