Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0
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 2:05am
Edited 27-Apr-12 20:04pm
v2
Comments
Sandeep Mewara at 24-Apr-12 11:29am
   
And where are you stuck? What is the issue?
Member 8233601 at 25-Apr-12 1:21am
   
i have problm in retriving img from database..
Sandeep Mewara at 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
0 Sergey Alexandrovich Kryukov 545
1 OriginalGriff 312
2 ravikhoda 300
3 Damith Weerasinghe 295
4 Tadit Dash 180
0 Sergey Alexandrovich Kryukov 10,974
1 OriginalGriff 6,667
2 Peter Leow 4,760
3 Abhinav S 3,813
4 Maciej Los 3,565


Advertise | Privacy | Mobile
Web01 | 2.8.140421.2 | Last Updated 28 Apr 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid