You must Sign In to post a response.
  • Category: ASP.NET

    How am upload and view images

    How am insert images and how to display from the database to browser in OLEDB.
    How am insert and get images from database and how to display on gridview from database to browser in OLEDB.
  • #761959
    There are two ways to do this .

    1. You can upload you images in your server and save insert the path of the image in your database. You can use this path in your image control.

    2. You can save the image in the binary format in the database. You can retrieve images and show it in the image controls. For retrive the image use the ashx. and give the ashx as src of the image control

    By Nathan
    Direction is important than speed

  • #761961
    Hai Paul,
    There are 2 ways to insert the images and display them to the control:-
    1. Save the path of the image to the database and keep the image in a folder so that while retrieving, retrieve the path from the database and then get the image from the folder.
    2. Save the image as the binary data to the database so here you need to convert the image to binary and the save. While retrieving, you need to again convert the binary to image and then use it for the control.
    Here the option #1 is more efficient as you save same the direct image with no conversion and just keep the path in to the database so that your database table size will not increase. If you convert the image to bytes and save and if later there are many images, the database size will grow and will not be good option.
    Hope it will be helpful to you.

    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)

  • #761965

    Place fileupload control, button control and gridview on the webform.

    protected void btnupload( object sender, EventArgs e)
    if (fileupload1.HasFile)
    int length =
    byte[] imgbyte = new byte [length];
    HttpPostedFile img =
    img.InputStream.Read(imgbyte, 0,
    OleDbConnection cn= new OleDbConnection(" your connection string");
    OleDbCommand cmd=new OleDbCommand("insert into images(img) values(@img)",cn);

    cmd.Parameters.Add( "@img" ,

    private void DisplayGrid()
    OleDbConnection cn=new OleDbConnection("your connection string");
    OleDbCommand cmd= new OleDbCommand("select * from images",cn);
    OleDbDataAdapter da = new
    DataTable dt = new DataTable();
    Gridview1.DataSource = dt;


    Sridhar Thota.

    Sridhar Thota.
    Editor: DNS Forum.

  • #761976
    Hello Paul,

    Refer the below links :

    Hope this will work for you.

    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #761981

    I think you got solution using above posts, if you still struck to achieve it refer below link, here i will explain how to insert images and how to get back images using .net code.

    this will help you to resolve your problem..

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • Sign In to post your comments