Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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
Dhaka,
Bangladesh
Posted 23-Dec-11 18:04pm
Rate this: bad
good
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[^]
  Permalink  
Rate this: bad
good
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)
       {
           try
           {
               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);
                   Fs.Close();
                   IMG.Image = Image.FromFile(dialog.FileName);
               }
               else
               {
                   MessageBox.Show("Select Image", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
               }
           }
           catch (Exception ex)
           {
               MessageBox.Show(ex.ToString());
           }
       }
 

Click save Button:
-----------
 
SqlCmd.Parameters.AddWithValue("@img", b);
  Permalink  

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



Advertise | Privacy | Mobile
Web03 | 2.8.141015.1 | Last Updated 24 Dec 2011
Copyright © CodeProject, 1999-2014
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