i need to store the images in database and retrive it through asp.net with c#.
these are given as
Query :
create database sss
go
use sss
go
create table ss_imgsample(imgid int identity(1,1),imgname varchar(150),imgfile image,primary key(imgid))
go
select * from ss_imgsample
go
Design :
file name :
choose the image file
SelectCommand="SELECT * FROM [ss_imgsample]">
Coding :
using System.Data.SqlClient;
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=sss;Integrated Security=True");
SqlCommand cmd = new SqlCommand();
protected void Button1_Click(object sender, EventArgs e)
{
attach();
}
protected void attach()
{
lbl_attachments.Text = "";
try
{
if (FileUpload1.HasFile)
{
Label1.Text = fileupload_img.FileName;
FileUpload1.SaveAs(Server.MapPath("~/Tempfiles/" + Label1.Text));
cmd = new SqlCommand("insert into ss_imgsample values('" + TextBox1.Text + "','" + FileUpload1.PostedFile.FileName + "') ", con);
if(cmd.EndExecuteNonQuery()>0)
{
Label1.Text="inserted";
}else{
Label1.Text="not done";
}
}
else
{
Label1.Text = "No file selected";
}
}
catch (Exception ex)
{ Response.Write(ex.Message); }
}
--------------------------------------
we have to insert the value in to database and show the value in grid view.
if u click on the grid view image then the page is redirected ti new page and displays the file name and image.
can any one help me to solve this
waiting for ur response.
responces highly appreciated
Ankit NandekarPosted May 20, 2011, 4:34 AM
http://www.c-sharpcorner.com/UploadFile/225bcd/5796/
Suthish NairPosted May 20, 2011, 4:24 AM
We do have lots of articles here, also..
Gowtham,
Check Our recommended articles section on right side..
What problem/error you are facing.
Do not copy paste lengthy code, upload your page as attachment only.
Dorababu MekaPosted May 20, 2011, 4:01 AM
http://www.aspsnippets.com/Articles/Display-images-from-SQL-Server-Database-in-ASP.Net-GridView-control.aspx
http://www.aspsnippets.com/Articles/Display-Images-in-GridView-Control-using-the-path-stored-in-SQL-Server-database.aspx