title: Update the image in binary format asp.net
body: <p>if i upload new image only than it stores the image else it store the null
  i want to rewrite the same binary image data to database if i not uploaded any image could anyone please help me out</p>
  
  <p>image file stored as varbinary(max) datatype format </p>
  
  <p>my code is</p>
  
  <p>aspx:</p>
  
  <pre><code> &lt;asp:TemplateField HeaderText="Image"&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:Image ID="Image1" runat="server" Height="100px" Width="100px" ImageUrl='&lt;%#"data:Image/jpg;base64,"+Convert.ToBase64String((byte[])Eval("Profile")) %&gt;' /&gt;
  
                              &lt;asp:HiddenField ID="imgurl" runat="server" Value='&lt;%# Eval("Profile") %&gt;' /&gt;
                          &lt;/ItemTemplate&gt;
                          &lt;EditItemTemplate&gt;
                               &lt;asp:HiddenField ID="hdProductPhoto" runat="server" Value='&lt;%#"data:Image/jpg;base64,"+Convert.ToBase64String((byte[])Eval("Profile")) %&gt;' /&gt;  
                              &lt;asp:FileUpload ID="imgUpload" runat="server" /&gt;&lt;/td&gt;
                          &lt;/EditItemTemplate&gt;
                      &lt;/asp:TemplateField&gt;
  </code></pre>
  
  <p>my csharp code is:</p>
  
  <pre><code> if (fuPhoto.FileName == "")
         {
  
             //System.Web.UI.WebControls.Image images = (System.Web.UI.WebControls.Image)GridView1.Rows[e.RowIndex].FindControl("userImages");
  
             //ImageContent = (byte[])(new ImageConverter()).ConvertTo(images, typeof(byte[]));
           HiddenField hdProductPhoto = (HiddenField)GridView1.Rows[e.RowIndex].FindControl("hdProductPhoto");
           string imgvalue = hdProductPhoto.Value;
  
  
           Response.Write("&lt;script&gt;alert('" + hdProductPhoto.Value + "')&lt;/script&gt;");
  
  
         }
         else
         {
             int length = fuPhoto.PostedFile.ContentLength;
               ImageContent = new byte[length];
             HttpPostedFile img = fuPhoto.PostedFile;
             img.InputStream.Read(ImageContent, 0, length);
     }
  </code></pre>