Click here to Skip to main content
12,761,780 members (36,007 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#3.0 C#
In my first form i am taking student detail with their image. using following codes:

To browse image..
<pre lang="cs">private void button2_Click(object sender, EventArgs e)

                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.Image = Image.FromFile(of.FileName);
                    pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                    imaeg = of.FileName;

            catch (Exception ex)
                MessageBox.Show("upload only jpg image!!");

To save image...
OleDbCommand cmd = new OleDbCommand("insert into Student values(@Myimage,@School)", conn);
                    cmd.Parameters.AddWithValue("@Myimage", imaeg);

In my second form i wana show all the information of student with their image in datagridview image column.

I am using the following code to retrive image:

private void button1_Click(object sender, EventArgs e)
 MemoryStream ms = new MemoryStream();
                        OleDbCommand cmd = new OleDbCommand("Select Myimage from student", conn);
                        byte[] image = (byte[])cmd.ExecuteScalar();
                        ms.Write(image, 0, image.Length);
                        foreach (DataGridViewRow row in dataGridView1.Rows)
                            row.Cells[0].Value = image.ToString();
                        Bitmap bitmap = new Bitmap(ms);

                        dataGridView1.DataSource= bitmap;

Error is:parameter is not plz provide proper code.
Posted 24-Apr-12 3:05am
Updated 27-Apr-12 21:04pm
Sandeep Mewara 24-Apr-12 11:29am
And where are you stuck? What is the issue?
Member 8233601 25-Apr-12 1:21am
i have problm in retriving img from database..
Sandeep Mewara 25-Apr-12 2:01am
It would be good if you share what problem and error if any.
Use Improve Question link to update it.

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 | Mobile
Web02 | 2.8.170217.1 | Last Updated 28 Apr 2012
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