Click here to Skip to main content
15,902,876 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have written this code for retrieving image from database to picturebox. I got these error 'Parameter is not valid' at this line 'pictureBox1.Image = Image.FromStream(stm);

C#
Byte[] imagebyte = new Byte[0];
imagebyte = (Byte[])(dr[Pic_Image]);
MemoryStream stm = new MemoryStream(imagebyte);
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.Image = Image.FromStream(stm);


It is storing that image as 0x53797374656D2E44726177696E672E4269746D6170 in database, would u pls solve this error.
Posted
Updated 10-Oct-14 0:26am
v3
Comments
George Jonsson 10-Oct-14 5:55am    
Is 0x really stored in the database?
Do you store the data as a string?
TarunKumarSusarapu 10-Oct-14 6:08am    
No I set datatype as image and it stored like this hexagonal
0x53797374656D2E44726177696E672E4269746D6170

Stored Images in Local Folder Name (Images) and Stored Images Name in Database

imgPic.src = string.Concat("Images/", Convert.ToString(objRow["ImagesName"]));
 
Share this answer
 
Comments
TarunKumarSusarapu 10-Oct-14 23:57pm    
I did n't understand what u wrote here.Can u please explain briefly
Hi Tarun,
U r fetching data from database correctly.
I think u have saved image in wrong format plz try below code
write image to byte array
C#
FileStream fs = new FileStream(@"C:\Users\ku102\Pictures\bitmap\usertile36.bmp", FileMode.Open, FileAccess.Read);
byte[] imgbnry = new byte[fs.Length];
fs.Read(imgbnry, 0, imgbnry.Length);
fs.Close();

pass byte array to backend for saving
C#
cmd.Parameters.Add("@img", System.Data.SqlDbType.Image);
cmd.Parameters["@img"].Value= imgbnry;
cmd.ExecuteNonQuery();


good luck ;-)
 
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