Click here to Skip to main content
15,902,112 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is my code. But i cannot display the image into picture box. i use image data type as imageContent for store image. Can i know how to solve this problem??


C#
SqlCommand sqlCmd = new SqlCommand("SELECT imageContent FROM printerBarCode pbc,PlantLayout pl WHERE pbc.Department=pl.Department,pbc.Location=pl.Location", con);
                        SqlDataAdapter SDA1 = new SqlDataAdapter(sqlCmd);
                        DataSet ds = new DataSet();  
                        SDA1.Fill(ds, "PlantLayout");  
                        int c = ds.Tables["Plantlayout"].Rows.Count; 
                         {   //BLOB is read into Byte array, then used to construct MemoryStream,  
                             //then passed to PictureBox.  
                            
                            Byte[] byteBLOBData = new Byte[0];  
                           byteBLOBData = (Byte[])(ds.Tables["PlantLayout"].Rows[c - 1]["imageContent"]);
                          
                         MemoryStream stmBLOBData = new MemoryStream(byteBLOBData);  
                           
                           pictureBox1.Image = Image.FromStream(stmBLOBData); 
                         }
Posted
Updated 20-Nov-12 17:42pm
v2

still pop up the message"Invalid data"...
 
Share this answer
 
 
Share this answer
 
USE THIS

MemoryStream stmBLOBData = new MemoryStream(byteBLOBData);  
                           
                           pictureBox1.Image = Image.FromStream(stmBLOBData); 
           Bitmap bmpImage = new Bitmap(ms);
            pictureBox1.Image = bmpImage ;
 
Share this 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