Click here to Skip to main content
16,022,413 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to insert an image and select it again from database into picturebox i have succeeded to insert it into database (image column) but when i select it again i get an error "The Parameter Is Not Valid" i think the insert statement has something incorrect,any sample of code for inserting an image into database and select it again?

Thanks.
Posted
Comments
Wonde Tadesse 4-Aug-11 17:06pm    
Tag your question properly. WinForms, WPF ...
Christian Graus 4-Aug-11 17:25pm    
The internet abounds with sample code that does this. Online articles will contain more detail than a forum reply, every time.
Wonde Tadesse 4-Aug-11 19:31pm    
Well, Can you post your code how you did it ?

 
Share this answer
 
Change your image in byte and then Insert in DataBase and Retrieve time retrieve that byte again and convert it again.
 
Share this answer
 
Comments
snake1 4-Aug-11 19:20pm    
i have already done this but there's an exception "The Parameter Is Not Valid" maybe i'm doing something wrong can you explain with some code please ?
divesh12 5-Aug-11 8:53am    
Please Post your code here.
snake1 20-Aug-11 3:18am    
Insert Step
//---------------
MemoryStream ms = new MemoryStream();
PBoxGuestImage.Image.Save(ms, ImageFormat.Jpeg);
Byte[] PicArray = new Byte[ms.Length];
ms.Position = 0;
ms.Read(PicArray, 0, PicArray.Length);

CMD.CommandText = "Insert Into TestTable(TestImage) Values (@ParTestImage)"
CMD.Parameters.AddWithValue("@ParTestImage", PicArray);
//---------------
this works great

Retrieve Step

Image NewImage;
byte[] content = (byte[])TestReader["TestImage"];
TestPictureBox.Image = null;
using (MemoryStream stream = new MemoryStream(content, 0, content.Length))
{
stream.Write(content, 0, content.Length);
NewImage = Image.FromStream(stream, true); //at this line i get the exception
}
TestPictureBox.Image = NewImage;

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