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");
}
vishnu sureshPosted Dec 31, 2014, 1:51 AM
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;
}
amitPosted Dec 31, 2014, 1:51 AM
Vinodh NarayananPosted Dec 31, 2014, 1:43 AM
vishnu sureshPosted Dec 31, 2014, 1:20 AM
Vinodh NarayananPosted Dec 30, 2014, 10:57 AM
Vinodh NarayananPosted Dec 30, 2014, 7:18 AM
Please follow this link....
https://aspdotnetvinodh.wordpress.com/2014/12/01/stroring-image-into-database-and-retrive-in-a-gridview-display-using-c/