Click here to Skip to main content
15,886,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want image upload ,save and fetch from database
plz help me
Posted

asp.net :
add a file uploader > in code behind save btn click event
if (fileuploadimages.hasfile)
{
C#
string filename = Path.GetFileName(fileuploadimages.PostedFile.FileName);
//Save images into Images folder
fileuploadimages.SaveAs(Server.MapPath("Images/"+filename));
// create a folder in your project named images


/*code for insert the image into DB
*/ create connection string and open here
SqlCommand cmd = new SqlCommand("Insert into Images(ImageName,ImagePath) values(@ImageName,@ImagePath)", con);
//Passing parameters to query
cmd.Parameters.AddWithValue("@ImageName", filename);
cmd.Parameters.AddWithValue("@ImagePath", "Images/" + filename);
cmd.ExecuteNonQuery();

}


code for display image
----------------


XML
<asp:GridView runat="server" ID="gvImages" AutoGenerateColumns="false" DataSourceID="sqldataImages" CssClass="Gridview" HeaderStyle-BackColor="#61A6F8" >
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" />
<asp:BoundField DataField="ImageName" HeaderText="Image Name" />
<asp:ImageField HeaderText="Image" DataImageUrlField="ImagePath" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="sqldataImages" runat="server"  ConnectionString="<%$ConnectionStrings:dbconnection %>"
SelectCommand="select * from Images" >
</asp:SqlDataSource>
 
Share this answer
 
 
Share this answer
 
Its not a little bit code its a Task.So refer the below links and try practice then you will get clear idea about your question.

http://www.aspdotnet-suresh.com/2011/01/how-to-insert-images-into-database-and.html[^]

http://www.dotnetgallery.com/kb/resource21-How-to-store-and-retrieve-images-from-SQL-server-database-using-aspnet.aspx[^]
 
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