Click here to Skip to main content
16,017,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I am developing a widows application using visual studio 2008 and SQL server 2005.

In the project I got an error while retreiving image from SQL 2005 database to Picturebox.
The error was "Unable to cast object of type 'System.Int32'to type System.Byte[]" while fetching image from database of int to byte array.

My code is as follows

C#
byte[] img = (byte[])cmd.ExecuteScalar();
              string str = Convert.ToString(DateTime.Now.ToFileTime());
              FileStream fs = new FileStream(str, FileMode.CreateNew, FileAccess.Write);
              fs.Write(img, 0, img.Length);
              fs.Flush();
              fs.Close();
              PicOldPatient.Image = Image.FromFile(str);

Please help me if any one knows....
Posted
Updated 21-Sep-11 21:46pm
v2
Comments
Dalek Dave 22-Sep-11 3:46am    
Edited for Code Block and Readability.

1 solution

As the error suggests, you need to convert the int return values to a byte array - read this discussion[^].
 
Share this answer
 

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