Save (Insert) Binary Image to database using Image Control in ASP.Net

Last Reply 10 months ago By pandeyism

Posted 10 months ago

Dear Team,

we have Displaying image from SQL database using image but while updating how to store Image Value to database with same Value.

Image Retrive & Save Code

// ImageRetriveCode
if (ds.Tables[0].Rows[0]["Image_Data"] != DBNull.Value)
    string imageUrl = "data:image/jpg;base64," + Convert.ToBase64String((byte[])ds.Tables[0].Rows[0]["Image_Data"]);
    imgDoctor.ImageUrl = imageUrl;

if (fileExtension.ToLower() == ".jpg" || fileExtension.ToLower() == ".bmp" || fileExtension.ToLower() == ".gif" || fileExtension.ToLower() == ".png")
    Stream stream = postedFile.InputStream;
    BinaryReader binaryReader = new BinaryReader(stream);
    byte[] bytes = binaryReader.ReadBytes((int)stream.Length);
    obj_Doc.Image_Data = bytes;
    obj_Doc.Image_Data = null;

  HTML Code

<div class="col-sm-6">
    <div class="form-group">
        <div class="profile-upload">
            <div class="upload-img"> 
                <asp:Image ID="imgDoctor" runat="server" Height="40px" Width="40px" class="rounded-circle m-r-5" />
            <div class="upload-input">
                <asp:FileUpload ID="fuImage" runat="server" class="form-control" />
This question does not have replies that have been liked.