Click here to Skip to main content
15,911,132 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am developing my project in visual studio2008 & i have form where i am browsing image into picturebox and save it into access2003 database.plz tell me the complete procedure how to accomplish this.
Posted

1 solution

Create a field in your database, make it OleObject type, call it myImage
Then:
C#
using (OdbcConnection con = new OdbcConnection(connectionString))
    {
    using (OdbcCommand com = new OdbcCommand("INSERT INTO myTable (myImage) VALUES (@IM)", con))
        {
        MemoryStream ms = new MemoryStream();
        MyPictureBox.Image.Save(ms,System.Drawing.Imaging.ImageFormat.Bmp);
        byte[] imageData = ms.ToArray();
        com.Parameters.AddWithValue("@IM", imageData);
        com.ExecuteNonQuery();
        }
    }
 
Share this answer
 
Comments
Member 8233601 10-Apr-12 3:31am    
I am using this code to load pictureBox1 on Button2_click event:

try
{
OpenFileDialog of = new OpenFileDialog();

DialogResult d = of.ShowDialog();

of.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
if (d == DialogResult.OK)
{
pictureBox1.BackgroundImage = Image.FromFile(of.FileName);
imaeg = of.FileName;
}
}
catch (Exception ex)
{
MessageBox.Show("upload only jpg image!!");

}
}


On save_click button event:



OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= |DataDirectory|/Schooldb.mdb");
OleDbCommand cmd = new OleDbCommand("insert into Student values(@Myimage)",conn);
cmd.Parameters.AddWithValue("@Myimage", imaeg);
}


My image get saved as Long Binary Data in Access2003 database.On login page i want to show image in picurebox on show_click event.
plz rply as soon as possible!!
OriginalGriff 10-Apr-12 3:34am    
So read it out and convert it back to an image.
Assuming you can read it from the DB (which is the reverse of writing it) and load it into a byte array:

MemoryStream ms = new MemoryStream(bytes);
Image returnImage = Image.FromStream(ms);

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