1

i have a table in my database in which contains an Image_ID, Image, Image_Name and Recipe_ID.

I am trying to edit these in a seperate form. So when a row in the dataGridView is selected it will open up in the edit form with the relevant areas filled out with data.

I am able to do it with all data apart from the Image. Obviously i need to somehow convert it as like i have done with the text fields but i have no idea on how to do so.

Edit Image Row

//Edit image row
        private void EditImageBtn_Click(object sender, EventArgs e)
        {
            try
            {
                EditImageForm Image = new EditImageForm();

                Image.imageidTxt.Text = this.imageGridView.CurrentRow.Cells[0].Value.ToString();
                //Image.picImg.Text = this.imageGridView.CurrentRow.Cells[1].Value.ToString();
                Image.nameTxt.Text = this.imageGridView.CurrentRow.Cells[2].Value.ToString();
                Image.recipeCombo.Text = this.imageGridView.CurrentRow.Cells[3].Value.ToString();

                Image.ShowDialog();
                loadImageTable();
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
2
  • What's the data type of the image ? Is it stored as a BLOB or varbinary in the database? And is your issue converting that back to a visual image? Commented Apr 5, 2016 at 17:35
  • @DavidOesterreich Image and its stored as Bytes. I have got my upload working but not able to retrieve it to view it correctly. Commented Apr 5, 2016 at 17:36

1 Answer 1

2

If your image is stored bytes, you can try something similar to the below to convert the bitmap to an Image type:

byte[] bitmap = this.imageGridView.CurrentRow.Cells[1].Value;    
Image image = Image.FromStream(new MemoryStream(bitmap))

More info: https://msdn.microsoft.com/en-us/library/9t4syfhh.aspx

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.