Click here to Skip to main content
15,888,280 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I wanted to save an image to SQL server database. (In an ASP.NET project)

Image is loaded from File upload button.

please any one suggest a way to accomplish this!

Thanks in Advance!

What I have tried:

<asp:FileUpload ID="fileup" runat="server" />
string sql = "INSERT INTO User_Info(Image) values(@image)";
SqlCommand cmd = new SqlCommand(sql,con);

string strname = fileup.FileName.ToString();
cmd.Parameters.AddWithValue("@image", strname);
Posted
Updated 3-Jun-16 2:49am
Comments
Richard Deeming 2-Jun-16 13:45pm    
1) What's the problem with the code you've posted?

2) Have you remembered to save the file somewhere on the server? The path of the file on the client won't do you much good. :)
F-ES Sitecore 3-Jun-16 5:58am    
Google "asp.net upload file and store in database" and you'll find hundreds of samples and tutorials.

You either save the Image to a folder and save the path in the db, or you save the image bytes into the database. Both have advantages and disadvantages. Lots of examples online if you get stuck.
 
Share this answer
 
Save the image in folder on server and save that image file's path in database table.
 
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