Lynn Emery

Lynn Emery

  • NA
  • 47
  • 56.7k

Upload image to SQL table

Oct 14 2013 10:55 AM
Hi, I wish to upload an image to an sql table.
So far I have used an open file dialogue and a picturebox where the user can browse for images and preview it. The code I have used for this is ;

//open the BtnBrowse dialog 
                    OpenFileDialog BrowseDialogue = new OpenFileDialog();
                   
            //Select filters on which file types to upload 
            BrowseDialogue.Filter = "Images Files (*.jpg; *.jpeg; *.gif; *.bmp; *.png:)|*.jpg; *.jpeg; *.gif; *.bmp; *png;";
                    if (BrowseDialogue.ShowDialog() == DialogResult.OK)
                    {
            //Preview the image in a picturebox
                        pictureBox1.Image = new Bitmap(BrowseDialogue.FileName);
            //Display image path in textbox 
                        textBox1.Text = BrowseDialogue.FileName;

The above code all works fine but I now want  to have an upload button where the image in the picturebox is uploaded to the database, I understand that there are two ways of doing this via file stream or memory stream.
The table name I wish to upload to is contents and the field name is image.
Could someone provide me with some information of how to go about this?
Many thanks for your help.


Answers (3)