Click here to Skip to main content
15,905,874 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
how to insert into image in sql server using .net c# ...and retrive image
Posted

See this CP Article
Save images in SQL Server
 
Share this answer
 
 
Share this answer
 
v3
Declare this:

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



Inserting Image:

C#
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();
                    Picturebox1.Image = Image.FromFile(dialog.FileName);
                }
                else
                {
                    MessageBox.Show("Select Image", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
 
Share this answer
 
Hi,

you have tons of article on codeproject.com about that:
Uploading / Downloading Pictures to / from a SQL Server[^]

Regards
Robert
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900