none
Adding a picture to access database to show in a functioning form RRS feed

  • Question

  • If there any way to add a picture to a microsoft access database so that it shows up in the results when that database is linked to an aspx page?  I know how to make a database and I know how to connect it to an aspx page/form etc, I have got all that to work, just dont know if its possible to add a picture that will show up in the results?
    Saturday, May 1, 2010 11:51 AM

All replies

  • If the image itself is in the database this gets tricky. You can't put images into a web page. You have to reference them such as <img src="link to the image" />

    What you'll need is another page with absolutely no HTML code in it. This other page must access the database, get the image based on some information you pass to it, then spit back the image and set the approrpriate response headers so that the browser knows it's an image. Your image html tags will look like <img src="imagehandler.aspx?imageid=PRIMARYKEY" /> where primary key is the primary key of the database row with the image.

    Here is an example done in VB.Net: http://www.velocityreviews.com/forums/t78173-display-an-image-from-access-database.html

    The response type for this one is BMP, you'll need to change it to your image type. such as JPG, PNG, etc.. You'll also want to make sure that the image is web friendly so a BMP or TIFF won't be acceptable for display.

    Saturday, May 1, 2010 1:18 PM
  • You don't add an image to a database, you add a "link to the image" to the database.
    Expression Web MVP
    Saturday, May 1, 2010 1:22 PM
  • Upload the image(s) to a folder in your site, and put their file names in the database.  It is easy to format the result of fetching that name from the database as the file URL, and make it display the image in the result field.

    E.g.:  Assume all images are in folder "images", and your page is at the root of the site, containing a control, for example, a FormView ,connected to the database.  Assume there is a Text field in the database called "imagename" containing the actual filenames, e.g.: mypicture.jpg

    Edit the Item Template of the FormView, and drag an asp.net image control into it. Edit the databindings of the image control, select "ImageUrl", Custom databinding, and enter: Eval("imagename","images/{0}")

    That will put a line in Code View, inside the <ItemTemplate> section, that looks like:

    <asp:Image runat="server" id="Image1" ImageUrl='<%# Eval("imagename","images/{0}") %>'

    This says: Get the value of "imagename", and format it by putting "images/" in front of it, and use that as the URL for the image control.

    • Proposed as answer by paladyn Saturday, May 1, 2010 7:17 PM
    Saturday, May 1, 2010 3:43 PM
  • Take a look at this step-by-step tutorial

    http://www.homepagedoctor.com/expressiontutorials/LinkingMultiplePicturesToGridviewResults.htm

    It does more than you need, but you can see how to set up the links to a picture there



    ClarkNK, A.K.A. HomePage Doctor
    HomePageDoctor.com -- Expression Web database tutorials
    Ownertrades.com -- Created with FP, Access, Bots and Wizards
    MyNumbersTracker.com -- Created with Expression, VWDExress, SQL Express, and ASP.NET.
    Sunday, May 2, 2010 1:55 AM