473,326 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Display image from a database get me ascii codes

All i wanna do is simple, I wanna display an image from an access database.

I try alot of things to no result. Like ascii code or nothing but a blank image with a red 'X'.

Here is the code :

<%
set conn=server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.jet.oledb.4.0"
conn.Open(server.MapPath("test1.mdb"))
set rs= conn.Execute("SELECT photo FROM photos where ID=1")
Response.ContentType="image/jpg"
Response.BinaryWrite(rs("photo"))
conn.Close
%>

I also tried a file named ShowPicture.asp and call it from another file like this:
<IMG SRC="ShowPicture.asp?PhotoId=1">

ShowPicture.asp
<%
'Declare Variables
Dim sql
Dim rs
Dim conn
Dim userID,str

userID = Request("PhotoId")
If userID = "" Then userID = 0

'Instantiate Objects
Set conn = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")

'Open connection
conn.Provider="Microsoft.jet.oledb.4.0"
conn.Open(server.MapPath("test1.mdb"))

'Get the specific image based on the ID passed in a querystring
str = "SELECT photo FROM photos where ID =" & userID
rs.Open str, conn,3,3

if rs.eof then 'No records found
Response.End
else 'Display the contents
Response.ContentType = "image/jpg"
Response.BinaryWrite(rs("photo"))
end if

'destroy the variables.
rs.Close
conn.Close
set rs = Nothing
set conn = Nothing
%>

I also try this :

<body>
<%
set conn=server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.jet.oledb.4.0"
conn.Open(server.MapPath("test1.mdb"))
set rs= conn.Execute("SELECT photo FROM photos where ID=1")
Response.ContentType="image/jpg"
%>

<img src="<%Response.BinaryWrite(rs("photo"))%>">

<% conn.Close %>
</body>

All i got is tons ascii codes.

Can you help me on this ?

thanx
Chris
Oct 28 '06 #1
2 2266
You are on the right path when referencing your image

e.g. <img src="file_name.asp?photoId=4">

Here is a copy of my file that works

<%@ Language=VBScript %>
<!--#include virtual="/_includes/connString.asp"-->
<%
Dim rs
Dim qry_getImage
Dim intPic_id

intPic_id = trim(Request.QueryString("id"))

' Clear out the existing HTTP header information
Response.Expires = 0
Response.Buffer = TRUE
Response.Clear

qry_getImage = "SELECT PHOTO_ALT_TEXT_EN, PHOTO_ALT_TEXT_FR, PHOTO_FILE "
qry_getImage = qry_getImage & "FROM CLASSIFIED_PHOTO "
qry_getImage = qry_getImage & "WHERE (PHOTO_ID = " & intPic_id & ") "

'Response.Write qry_getImage
' response.end

set rs = Server.CreateObject("ADODB.Recordset")
Set rs = conn.Execute(qry_getImage)

if not (rs.BOF and rs.EOF) then
' Change the HTTP header to reflect that an image is being passed.
Response.ContentType = "image/gif"
Response.BinaryWrite rs("PHOTO_FILE")
Response.Write rs("PHOTO_ALT_TEXT_EN")
Response.Write ("<br>")
Response.Write rs("PHOTO_ALT_TEXT_FR")
else
Response.Redirect "/_images/spacer.gif"
end if

Response.End
%>
Nov 16 '06 #2
Actually, scratch the part where I write the caption text as well, this has to be done seperatly.
Nov 16 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: John Smith | last post by:
I know that uploading an image to a database has been covered, oh, about 3 trillion times. However, I haven't found anything covering uploading to a MySQL database with .net. Please don't...
11
by: Kai Bohli | last post by:
Hi all ! I need to translate a string to Ascii and return a string again. The code below dosen't work for Ascii (Superset) codes above 127. Any help are greatly appreciated. protected...
3
by: harish | last post by:
Hi friends I am facing problem as follow I can't display image from SQL Database to Picture box Control. Here are the codes that I am writing Dim arrPicture() As Byte = _
6
by: Ben | last post by:
I am trying to write codes in VB.net to display 3 images in series on a Webform with each image being displayed in the same box for 5 seconds. I am trying to use Timer and image button, don't...
9
by: simchajoy2000 | last post by:
Hi, I know what the ASCII Character Codes are for the 2nd and 3rd powers in VB.NET but I can't find the 6th power anywhere - does anyone know what it might be or if it even exists? Joy
3
by: den 2005 | last post by:
Hi everyone, Here is code working on..Trying to insert record with a column with Image or VarBinary datatype in sql database from a existing jpeg image file, then retrieve this image from...
1
by: Objectifnet | last post by:
What I really want to do is to be able to link two pages together using an ID, The table involved displays an image stored on the File Server that has the image details stored in the Database called....
5
by: CC | last post by:
Hi: I'm building a hex line editor as a first real Python programming exercise. Yesterday I posted about how to print the hex bytes of a string. There are two decent options: ln =...
6
by: msmjsuarez | last post by:
how can i display both image and other information in the web page using php? i'm using mysql database. I do displaying the image only but i want to display both other information from the database...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.