Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi,
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:
VB
'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..
Posted
Updated 10-Mar-13 21:16pm
v3
Comments
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];
b1=(Byte[])ds.Tables[0].Rows[i][52];
MemoryStream ms=new MemoryStream(b1);
ms.Read(b1,0,Convert.ToInt32(ms.Length));
ds.Tables[0].Rows[i][52]=b1;
emp_pic.Image=Image.FromStream(ms);//at this point error is shown as:Parameter is not valid.
empPic.SizeMose=System.WindowsForms.PictureBoxSizeMode.StretchImage;
ms.close():

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