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.
    or
    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.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #761965
    Hi

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

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

    cmd.Parameters.Add( "@img" ,
    OleDbType.Image).Value=imgbyte;

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

    Regards

    Sridhar Thota.

    Sridhar Thota.
    Editor: DNS Forum.

  • #761976
    Hello Paul,

    Refer the below links :

    http://www.c-sharpcorner.com/uploadfile/e628d9/inserting-images-into-ms-access-file-using-oledb/

    http://www.c-sharpcorner.com/UploadFile/dbeniwal321/reading-and-saving-images-fromto-a-database-using-C-Sharp/

    Hope this will work for you.

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

  • #761981
    Hi,

    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.

    http://www.dotnetspider.com/resources/45091-Insert-Edit-Update-Delete-Get-back-Image-from-DataBase.aspx

    this will help you to resolve your problem..

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

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


Sign In to post your comments