3
OleDbCommand and = new OleDbCommand();
c.Open();
and.Connection = c;
and.CommandText = "SELECT * FROM MaleShoes WHERE IDhere=ID ";
OleDbDataReader read = and.ExecuteReader();
while (read.Read())
{
    label6.Text = (read[1].ToString());
    textBox1.Text = (read[2].ToString());
    pictureBox1.Image = (read[3].ToString());  
}

c.Close();

I got this error:

Error 1 Cannot implicitly convert type 'string' to 'System.Drawing.Image'

How should I fix it?

My pictures are in my database on the third column.

Mohammad Dehghan
  • 17,853
  • 3
  • 55
  • 72
YOUn'Me
  • 107
  • 1
  • 3
  • 9

4 Answers4

6

If you your database column contains the path to the image file, you should write:

pictureBox1.Image = Image.FromFile((string)read[3]);

If it is the image data (binary), you should write:

var bytes = (byte[])read[3];
using(MemoryStream ms = new MemoryStream(bytes))
{
    pictureBox1.Image = Image.FromStream(ms);
}
Mohammad Dehghan
  • 17,853
  • 3
  • 55
  • 72
4

Hope this help (in case you are storing a binary):

pictureBox1.Image = byteArrayToImage((byte[])read[3]);  

And your method

public Image byteArrayToImage(byte[] byteArrayIn)
{
     MemoryStream ms = new MemoryStream(byteArrayIn);
     Image returnImage = Image.FromStream(ms);
     return returnImage;
}
Alex
  • 8,827
  • 3
  • 42
  • 58
1

you can also use this

  byte[] imagebyte = (byte[])read[3].ToString();

  MemoryStream ms = new MemoryStream();
  ms.Write(imagebyte, 0, imagebyte.Length);
  Bitmap bmp = new Bitmap(ms);
  pictureBox1.Image = bmp;
Pyromancer
  • 2,429
  • 5
  • 19
  • 28
0

You can try this:

MemoryStream ms = new MemoryStream((byte[])read[1]);

pictureBox1.Image = Image.FromStream(ms);
Vishal Suthar
  • 17,013
  • 3
  • 59
  • 105