Click here to Skip to main content
15,919,028 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am making a project in c# winforms using sql server 2005.I cannot retrieve image from database into picturebox.A messagebox is shown saying:
'Unable to cast object of type system.int32' to type 'system.byte[]'

I am stuck at this point,can't figureout what to do.Please help me out as soon as possible..
Updated 10-Mar-13 21:16pm
pradiprenushe 11-Mar-13 3:14am    
Your error is self explanatory. You are trying to read some int value (may be int column) into byte array.
Dev Gupta from Mumbai,India 11-Mar-13 3:22am    
yup,my image is stored in 52th column of my table,so what to do know?please help me....
pradiprenushe 11-Mar-13 3:26am    
Use column name while reading value
OriginalGriff 11-Mar-13 4:09am    
Without seeing your code, we can't tell exactly what problem you are having.
Post the code fragment that accesses the database, and indicate where it throws the error.
Use the "Improve question" widget to edit your question and provide better information.
Dev Gupta from Mumbai,India 12-Mar-13 3:30am    
here's the code:
byte[]b1=new byte[0];
MemoryStream ms=new MemoryStream(b1);
emp_pic.Image=Image.FromStream(ms);//at this point error is shown as:Parameter is not valid.

Instead of ds.Tables[0] ,i also tried ds.Tables["employee"].bt result was same..

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