Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am saving image file into the database as binarydata and retrieving the image file from the database. I am using response.write() to display the image file.
The problem is response.write() clearing all the label,button,textbox fields in my page.But i need button in my page to increase the count.
CODE:
protected void btnsave2_Click(object sender, EventArgs e)
       {
           imag++;
           byte[] imagebyte = new byte[FileUpload1.PostedFile.InputStream.Length + 1];
           FileUpload1.PostedFile.InputStream.Read(imagebyte, 0, imagebyte.Length);
           cmd = new MySqlCommand("Insert Into db_image (Image,ImageId) values (@imag,@imageid)", con);
           cmd.Parameters.AddWithValue("imag", imagebyte);
           cmd.Parameters.AddWithValue("imageid", imag.ToString());
           cmd.ExecuteNonQuery();


       }

protected void btnretr2_Click(object sender, EventArgs e)
       {
           cmd = new MySqlCommand("Select Image from db_image where ImageId='" +txt_imageid.Text.Trim()+ "' ", con);
           dr = cmd.ExecuteReader();
           while (dr.Read())
           {
               Response.BinaryWrite((byte[])dr["Image"]);


           }
       }

Help me.
Posted

1 solution

Instead of writing to Response you should use an object like this and still keep your label on page (in which you will write the count).

Check this

Control to Display Binary Images in ASP.NET[^]


Cheers
 
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