Click here to Skip to main content
13,297,799 members (49,359 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hello sir,
I am a trainee of c#. recently I got a problem to save a image (jpg format) from a picturebox to database. I am using sql database. and visual studio 2008. i can show any image to picture box in my window application. but could not save that image in database.

plz if u could solve my problem.

thank you,
Md. Shafiqul Azam
Posted 23-Dec-11 19:04pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Hi we do not save image in database , we save the only image path database, so you should be save your image in a folder, and its path in database, and for more information you can visit this url...Store or Save images in SQL Server[^]
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Declare this variable:

Byte[] b = null;
FileStream Fs = default(FileStream);

click the pictureBox1 then write this coding:

private void PictureBox1_Click(object sender, EventArgs e)
               OpenFileDialog dialog = new OpenFileDialog();
               dialog.Filter = "JPEG(*.jpeg)|*.jpeg|GIF(*.gif)|*.gif|PNG(*.Png)|*.png|AllFiles|*.*";
               if (dialog.ShowDialog() == DialogResult.OK)
                   Fs = File.Open(dialog.FileName, FileMode.OpenOrCreate);
                   b = new Byte[Fs.Length];
                   Fs.Read(b, 0, b.Length);
                   IMG.Image = Image.FromFile(dialog.FileName);
                   MessageBox.Show("Select Image", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
           catch (Exception ex)

Click save Button:

SqlCmd.Parameters.AddWithValue("@img", b);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.171207.1 | Last Updated 24 Dec 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100