Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a datagridview that display image retreived from a database, i want that when ever a user select the row e.g that has id column an picture column, and click on a button the image should be pick from the image column and diplayed on a picturebox
pls any help on how to do this.
Thanks
Posted

1 solution

Hi ,
Check this
With the same Datasource you are using to bind your DataGrid
C#
using (SqlConnection con = new SqlConnection(@"Data Source=pc\SQLEXPRESS;Initial Catalog=test;Persist Security Info=True;User ID=sa;Password=***"))
            {
                con.Open();
                using (SqlCom
mand cmd = new SqlCommand("select * from ImageInsert", con))
                {
                    SqlDataAdapter adpt = new SqlDataAdapter(cmd);
                    DataSet ds = new DataSet();
                    adpt.Fill(ds);
                    DataRow Row;
                    Row = ds.Tables[0].Rows[0];
                    byte[] MyImg = (byte[])Row[1];
                    MemoryStream ms = new MemoryStream(MyImg);
                    Image img = Image.FromStream(ms);
                    pictureBox1.Image = img;

                }
            }

Best Regards
M.Mitwalli
 
Share this answer
 
Comments
Ese Ochuko 28-Aug-12 8:28am    
Thanks vry much that waz a eye opener
Mohamed Mitwalli 28-Aug-12 9:38am    
Your welcome If it help you mark it as answer
[no name] 28-Aug-12 13:18pm    
correct answer.
+5
Mohamed Mitwalli 28-Aug-12 13:44pm    
Thanks Sourav :)
[no name] 28-Aug-12 14:13pm    
Why he is not accepting the answer?

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