Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I am able to add and retrieve image from database.
PROBLEM: I want to update image in database i.e. to replace the existing image with the new one or the same which i have retrieved from the database.

I am using this code to retrieve image from database and its working,
MemoryStream ms = new MemoryStream((byte[])dr["Photo"]);
curImage = Image.FromStream(ms);
pbImage.Image = curImage;


I am using this code to update image in database and its not working,
FileStream file = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Read);
byte[] rawdata = new byte[file.Length];
file.Read(rawdata, 0, System.Convert.ToInt32(file.Length));
file.Close();
cmdSave.Parameters.Add(new SqlParameter("@photo", rawdata));


Suppose the user doesn't want to update image, he just want to update other values such as name,contactno. etc and when the user clicks the update button the existing image should get updated along with other values

All i need is to update the image in database with the same image that i have retrieved or with a new image.

I have not got the solution yet. The 1st answer is not the solution.
please help...asap
Posted
Updated 13-Apr-10 6:07am
v4
Comments
Amir Mahfoozi 17-Dec-11 6:15am    
Please provide your update query.

Perhaps post some code?

'It's not working' is a bit difficult to determine !
 
Share this answer
 
I'm facing the same problem... please any one can help us!!!!?
 
Share this answer
 
i need help on this problem as well.
does anyone have the code how to do it
 
Share this answer
 
Comments
Prashant Srivastava LKO 17-Dec-11 6:24am    
:)
Member 8421339 17-Dec-11 6:31am    
NYCE ANSWER PRASHANT :) LMAO
You need to convert to\from byte array to save into the database

Here's a simple example

Save An Image Into SQL Server 2000 Database[^]
 
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