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:
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)
        {

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


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

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

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();
                        conn.Open();
                        
                        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;
                        conn.Close();
                    }
             }


Error is:parameter is not valid.so plz provide proper code.
Posted
Updated 27-Apr-12 20:04pm
v2
Comments
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)



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