Results 1 to 3 of 3

Thread: Display image from SQL 7

  1. #1

    Thread Starter
    Hyperactive Member scuzymoto's Avatar
    Join Date
    Aug 1999
    Location
    Washington State
    Posts
    316

    Display image from SQL 7

    I have a SQL 7 database full of images (datatype Image). I also have an ASP page that allows the user to type in the name of the person they want to look up a picture of. I can retrieve the record no problem, I just need to know how to display the image on the page once Ive located it.
    SCUZ

  2. #2
    Fanatic Member Ianpbaker's Avatar
    Join Date
    Mar 2000
    Location
    Hastings
    Posts
    696
    Hi scuzymoto

    Image fields in ASP are decidedly dodgy things and I don't think there is any way of displaying them on an ASP page ( I haven't seen anyway). The alternative is to just have all you images sitting in a folder and store there address in the database so you can then use <img src="<% myRecordset("MyFileAddressFIeld")%>">

    Hope this helps

    Ian
    Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!

  3. #3

    Thread Starter
    Hyperactive Member scuzymoto's Avatar
    Join Date
    Aug 1999
    Location
    Washington State
    Posts
    316

    fine I don't need help...

    I didn't have the option of keeping the images in a directory and keeping the paths in the database. The database HAD to contain the images in an image datatype field. So for those of you who have struggled with this... here is how you do it. I spent the day at the library figuring this out but its actually kinda simple and works like a charm:

    First you create an asp file to obtain the image:

    Code:
    <% @LANGUAGE="VBSCRIPT" %>
    <% Option Explicit %>
    <%
    dim iPictureID
    iPictureID = Request("PictureID")
    
    dim objConn
    set objConn = server.createobject("ADODB.Connection")
    objConn.ConnectionString = "Provider=MSDASQL.1;Password=mypassword;Persist Security Info=True;User ID=myuser;Data Source=mydatasource;Initial Catalog=mytable"
    objConn.Open
    
    dim objRS
    set objRS = server.createobject("ADODB.Recordset")
    objRS.ActiveConnection = objConn
    
    dim strSQL
    strSQL = "select image from images where image_number = " & iPictureID
    
    objRS.Open strSQL
    
    if not objRS.EOF then
      response.contenttype = "image/jpeg" 'defines type of data
      response.binarywrite objRS(0) 'writes the data
    end if
    
    objRS.close
    objConn.close
    set objRS = nothing
    set objConn = nothing
    %>
    Then you create a file to request the image: (this one is easy)

    Code:
    <%
    response.write "<IMG SRC=""getpicture.asp?pictureID=" & "123456" & """>"
    %>
    And you display the picture from your database under the 123456 key!!
    SCUZ

Posting Permissions

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



Click Here to Expand Forum to Full Width