Assuming you're using C# and Windows Forms, you can follow these steps:
Retrieve the image from the database as a byte array.
Convert the byte array into a MemoryStream.
MemoryStream ms = new MemoryStream(byteArray);
Use the FromStream static method of the Image class to create an Image object from the MemoryStream.
Image image = Image.FromStream(ms);
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;
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2022-03-29 11:00:00 +0000
Seen: 12 times
Last updated: Jul 17 '21
What does "waiting for handler commit" mean in relation to the slow writes experienced in MySQL 8?
How is the Node.js Digital Ocean MySQL database related?
What is the process of integrating a Python task queue in a Flask application?
What is the difference between indexing in Elasticsearch and MongoDB?