Results 1 to 7 of 7
  1. #1
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Store URL to an image

    Hi,

    I've read numerous posts that suggest storing a web url to a photo in the sql databse vs the image itself but can find nothing on the specifics of how to do this. Am I simply storing the url that is in the source code. For example, the url is:

    ImageUrl="~/App_Data/Photos/WeddingPhotos/Wedding1/1.jpg"

    or is there a way to store it so that when the database is viewed the photo opens with it?

    Thanks,
    Leesha

  2. #2
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Store URL to an image

    <img src=/S/hello.gif border=0 alt=hello width=25 height=29> Leesha

    I am assuming that by your synatx, you are using ASP.NET. Correct?
    Jerry

  3. #3
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Store URL to an image

    Hi Jerry!!! How are you??

    You are good! Asp.net 2.0. Stumbled on it quite by accident due to my increasing frustration with FP limitations and the ever growing need to learn asp and now sql server 2005. Ugh.....................so much to learn! Anyway, as usual, I'm clueless but I'm certainly learning a lot! Any thoughts on this?

    Leesha

  4. #4
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Store URL to an image

    Thanks Jerry!! I'm encouraged in that it actually makes sense reading it, not that I could ever write it from scratch, but its no longer looking like Greek!!!

    I can't wait to give it a try.

    Leesha

  5. #5
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Store URL to an image

    <P ID="edit" class=small>(Edited by Jezza on 07-Mar-08 19:14. To fix some syntax errors)</P>Hi Leesha

    The syntax goes a bit like this:

    <pre><%@ Import Namespace="System.Data.SqlClient" %>

    <Script Runat="Server">

    Sub Page_Load
    If Not IsPostBack Then
    Dim conMyData As SqlConnection
    Dim cmdSelect As SqlCommand
    Dim dtrImages as SqlDataReader


    conMyData = New SqlConnection("Server=localhost;UID=sa;PWD=secret; Database=myData")

    conMyData.Open
    cmdSelect =New SqlCommand( "Select myImageURL From tblImages", conMyData)
    dtrImages =cmdSelect.ExecuteReader()

    rptImages.Datasource =dtrImages
    rptImages.DataBind()

    dtrImages.Close()
    conMyData.Close()

    End If
    End Sub

    <html>

    <body>
    <form Runat="Server">

    <asp:Repeater
    ID="rptImages"
    Runat="Server">

    <ItemTemplate>


    <asp:Image
    ImageURL='<%# Container.DataItem( "myImageURL" ) %>'
    Runat="Server" />
    </ItemTemplate>
    </asp:Repeater>
    </form>
    </body>
    </html>
    </pre>

    Jerry

  6. #6
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Store URL to an image

    Leesha

    I have made some changes to the code as I had a couple of typos in it, but fingers crossed it should assist you.
    Jerry

  7. #7
    Silver Lounger
    Join Date
    Jan 2002
    Posts
    1,615
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Store URL to an image

    Hi Jerry,
    I played around with your code (thanks for your postback otherwise I'd never have found the typos LOL) and then found the imagecontrol and ended up using that which did what I needed it to. It took me forever to get the syntax correct but it finally worked. Now I'm getting errors when I go to edit the field from a form and the delete isn't working. I'll post the info to another thread.

    Thanks!
    Leesha

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •