Click here to Skip to main content
12,242,492 members (62,156 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)
        {
 
            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 24-Apr-12 3:05am
Edited 27-Apr-12 21: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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 28 Apr 2012
Copyright © CodeProject, 1999-2016
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