Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Assuming you're using C# and Windows Forms, you can follow these steps:

  1. Retrieve the image from the database as a byte array.

  2. Convert the byte array into a MemoryStream.

    MemoryStream ms = new MemoryStream(byteArray);

  3. Use the FromStream static method of the Image class to create an Image object from the MemoryStream.

    Image image = Image.FromStream(ms);

  4. Set the Image property of the PictureBox control to the Image object.

    pictureBox1.Image = image;

Here is an example code snippet:

// Assuming connection is a SqlConnection object
SqlCommand command = new SqlCommand("SELECT ImageColumn FROM Table WHERE ID=1", connection);
byte[] byteArray = (byte[]) command.ExecuteScalar();
MemoryStream ms = new MemoryStream(byteArray);
Image image = Image.FromStream(ms);
pictureBox1.Image = image;