Click here to Skip to main content
14,696,502 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
using (SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Documents and Settings\\meekun.poon\\My Documents\\Visual Studio 2008\\Projects\\TrackLocation\\TrackLocation\\barcodePrinter.mdf;Integrated Security=True;User Instance=True"))
                    {
                        conn.Open();
                        using (SqlCommand cmd = new SqlCommand("SELECT ImageName FROM Image WHERE ImageID='PL001'", conn))
                        {
                            SqlDataAdapter adpt = new SqlDataAdapter(cmd);
                            DataSet dataSet = new DataSet();
                            adpt.Fill(dataSet, "Image"); 
                            DataRow Row;
                            Row = dataSet.Tables["Image"].Rows[0];
                            byte[] MyImg = (byte[])Row[0];
                            MemoryStream ms = new MemoryStream(MyImg);
                            ms.Position = 0;
                                
                            Image img = Image.FromStream(ms); //error 
                            
                         pictureBox1.Image = img;
                            
                        }
                        conn.Close();
                    }

how to solve this problem??? imagename is image data type!! error message->parameter is not valid. URGENT!!! thanks
Posted
Updated 28-Jan-20 16:20pm
v3

1 solution

   
Comments
WinnieMeeKun 27-Nov-12 23:03pm
   
my code only the Image img = Image.FromStream(ms);->got problem....why will like that??
[no name] 27-Nov-12 23:05pm
   
What kinda error you're getting ?
Patel Shailendra 28-Nov-12 2:52am
   
hi WinnieMeeKun
how you save image in database binary format or saving path of image and keeping you images in folder.
WinnieMeeKun 28-Nov-12 0:46am
   
parameter is not valid-> error message..how to solve it???
WinnieMeeKun 28-Nov-12 3:11am
   
INSERT INTO Image
(ImageID,ImageName,Department)
VALUES ('PL002','C:\Documents and Settings\meekun.poon\My Documents\My Pictures\original plant layout\OSA Rework edited.jpeg','OSA REWORK')
***this is how i insert data into ms sql server 2005.
Satish rathore 28-Nov-12 3:25am
   
Please convert Image into binary before inserting into database.
WinnieMeeKun 28-Nov-12 9:37am
   
not already in binary form??? i save layout as image data type...i don't understand your meaning...

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