I am having a web application. In which i have uploaded some images in my database, now i want to show that table in my gridview with all the images not a single image.
I have googled it so much but did not find the right answer.
My table design is
create table pictures
(
pic image,
name varchar(50)
)
I am saving my images like this.
protected void Button2_Click(object sender, EventArgs e)
{
if (FileUpload2.HasFile)
{
try
{
string filename = FileUpload2.FileName;
string path = "~\\uploads\\" + filename.Trim();
FileUpload2.PostedFile.SaveAs(Server.MapPath("~\\uploads\\" + filename.Trim()));
SqlConnection conn = new SqlConnection(connstr);
SqlCommand cmd = new SqlCommand("insert into pictures values('" + path + "', '" + filename + "')", conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
Label1.Text = "file uploaded successfully";
But now i want to retrieve these images in a gridview from database.
SqlConnection conn = new SqlConnection(connstr);
SqlCommand cmd = new SqlCommand("select pic from picture", conn);
conn.Open();
Byte[] img = (Byte[])(cmd.ExecuteScalar());
GridView2.DataSource = img;
GridView2.DataBind();
conn.Close();
I have used image field, item template but could not succeed.
Please help me.
Thanx in advance
Rakesh Sharma