Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-server-2005 C#
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 27-Nov-12 16:44pm
Edited 27-Nov-12 20:25pm
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
WinnieMeeKun at 27-Nov-12 23:03pm
   
my code only the Image img = Image.FromStream(ms);->got problem....why will like that??
Krunal R at 27-Nov-12 23:05pm
   
What kinda error you're getting ?
shailendra194878 at 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 at 28-Nov-12 0:46am
   
parameter is not valid-> error message..how to solve it???
WinnieMeeKun at 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 at 28-Nov-12 3:25am
   
Please convert Image into binary before inserting into database.
WinnieMeeKun at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 494
1 CHill60 405
2 OriginalGriff 345
3 PIEBALDconsult 285
4 BillWoodruff 213


Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 28 Nov 2012
Copyright © CodeProject, 1999-2014
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