Click here to Skip to main content
15,908,020 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am trying to store and retrieve an image in sql using c# form. i am able to store
the image into the db but i get an error message when i try to search and display the immage on the form

on my save button i have

C#
var
_with1 = person;
_with1.ID = this.txtClientid.Text;
_with1.myPicture  = imgPerson.Image;



on the search button i have

_with3.imgPerson.Image = person.myPicture.ToString();

but i get an error message from the serch button
Cannot implicitly convert type 'string' to 'System.Drawing.Image'

pls help
Posted

1 solution

Take off the ToString method call.
If person.myPicture is an Image, you can use it directly.
 
Share this answer
 
Comments
mikeoabban 24-Feb-12 5:38am    
i removed the ToString and got this error message
Cannot implicitly convert type 'object' to 'System.Drawing.Image'. An explicit conversion exists (are you missing a cast?)
OriginalGriff 24-Feb-12 6:07am    
Then you need to check what you have declared (and assigned to) the person.myPicture property as.
If it is an Image, you wouldn't get the error, so you need to know what it actually is...
mikeoabban 24-Feb-12 6:35am    
i noticed in the class i used picture = dr["picture"].ToString();
i removed the ToString and got an error msg
Cannot implicitly convert type 'object' to 'string'. An explicit conversion exists (are you missing a cast?)

what should i do pls
OriginalGriff 24-Feb-12 7:08am    
dr["picture"] implies you are getting this from a database, and that it had a ToString call on it implies that the DB stores the path to the file (or a partial path at least). You need to load the Image from the file:
Image myImage = Image.FromFile((string) dr["picture"]);
I could be wrong - but it's a good guess based on current information!

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