I have a code to store images directly to the database in binary format. But I cannot retrieve the image. This is my image uploading code.
if(FileUpload2.HasFile)
{
if (FileUpload2.PostedFile.ContentType == "image/jpg" || FileUpload2.PostedFile.ContentType == "image/jpeg" || FileUpload2.PostedFile.ContentType == "image/png")
{
int filelength = FileUpload2.PostedFile.ContentLength;
byte[] imagebytes = new byte[filelength];
FileUpload2.PostedFile.InputStream.Read(imagebytes, 0, filelength);
SqlCommand cmd = new SqlCommand();
//cmd.CommandText = "Insert into login(image) values(@image)";
//cmd = new SqlCommand("update login set image=@image where uname=@uname", con);
cmd.CommandText = "update login set image=@image where uname=@uname";
cmd.Parameters.AddWithValue("@uname", TextBox1.Text);
cmd.Connection = con;
cmd.Parameters.AddWithValue("@image", imagebytes);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
Response.Write("Image saved to database");
}

Vinodh NarayananRank #175 · 13.8K reputationPosted Dec 30, 2014, 2:18 AM EST
Please follow this link....
https://aspdotnetvinodh.wordpress.com/2014/12/01/stroring-image-into-database-and-retrive-in-a-gridview-display-using-c/
Vinodh NarayananRank #175 · 13.8K reputationPosted Dec 30, 2014, 5:57 AM EST
Vinodh NarayananRank #175 · 13.8K reputationPosted Dec 30, 2014, 8:43 PM EST
vishnu suresh53 reputationPosted Dec 30, 2014, 8:20 PM EST
amit10 reputationPosted Dec 30, 2014, 8:51 PM EST
vishnu suresh53 reputationPosted Dec 30, 2014, 8:51 PM EST
protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e)
{
//GridView1.Visible = false;
GridViewRow row = GridView1.SelectedRow;
TextBox1.Text = row.Cells[1].Text;
TextBox2.Text = row.Cells[2].Text;
//Image1.ImageUrl = row.Cells[3].Text;
ImageMap1.ImageUrl = row.Cells[3].Text;
}