ASP image from SQL Server

M

MVM

I am using SQL server and ASP to create a webpage and display images
directly from the database. My code is working fine, the issue I am having
is when a photo is not in the database. For example, we have a table of
homes and a table of photos. Not every home has a photo. So when I search
the photo table for a photo that does not exist I want to display a "No
Image Found" gif. Below is my code.

homedetail.asp:
<img src='photo.asp?GID=" & objRS("GID") & "' width='320' height='240'>



photo.asp:
intGID = Request.QueryString("GID")
....
strSQL = "SELECT PHOTO FROM GIS_PHOTO_VIEW WHERE GID =" & intGID
....
intRecordCount = objRS.RecordCount

If intRecordCount = 0 Then
Response.Write "images/noimage.gif" <--- problem statement
Else
Response.ContentType = "image/jpg"
Response.BinaryWrite objRS("PHOTO")
End If


This works perfect when there is a photo in the database. But when the
record count is 0, it passes the text "images/noimage.gif" back to
homedetail.asp and homedetail displays nothing. How do I get it to pass
the actual image "noimage.gif" back to homedetail.asp?
Thansk!
MVM
 
M

McKirahan

MVM said:
I am using SQL server and ASP to create a webpage and display images
directly from the database. My code is working fine, the issue I am having
is when a photo is not in the database. For example, we have a table of
homes and a table of photos. Not every home has a photo. So when I search
the photo table for a photo that does not exist I want to display a "No
Image Found" gif. Below is my code.

homedetail.asp:
<img src='photo.asp?GID=" & objRS("GID") & "' width='320' height='240'>



photo.asp:
intGID = Request.QueryString("GID")
...
strSQL = "SELECT PHOTO FROM GIS_PHOTO_VIEW WHERE GID =" & intGID
...
intRecordCount = objRS.RecordCount

If intRecordCount = 0 Then
Response.Write "images/noimage.gif" <--- problem statement
Else
Response.ContentType = "image/jpg"
Response.BinaryWrite objRS("PHOTO")
End If


This works perfect when there is a photo in the database. But when the
record count is 0, it passes the text "images/noimage.gif" back to
homedetail.asp and homedetail displays nothing. How do I get it to pass
the actual image "noimage.gif" back to homedetail.asp?
Thansk!
MVM


Perhaps you want this:

Response.Write "<img src='images/noimage.gif' border='0' alt='No image
available.'>"
 
M

MVM

McKirahan said:
Perhaps you want this:

Response.Write "<img src='images/noimage.gif' border='0' alt='No image
available.'>"

Normally that would be correct, the problem is that I already have an <img
src=...> in my original .asp file, so I am needing to pass an image that is
not in the database, in a binary format instead of the normal image link
format. So that doesn't work, because then the browser sees <img src=<img
src='images/noimage.gif'...>> Which obviously does not work.
 
M

McKirahan

MVM said:
Normally that would be correct, the problem is that I already have an <img
src=...> in my original .asp file, so I am needing to pass an image that is
not in the database, in a binary format instead of the normal image link
format. So that doesn't work, because then the browser sees <img src=<img
src='images/noimage.gif'...>> Which obviously does not work.

I don't fully understand.

Is "images/noimage.gif" a file? A path is specified, so it must be, right?

You could put it in the database (e.g. GID=0) and retrieve it before looking
for any other image then use it if no image exists.
 
M

MVM

McKirahan said:
table

I don't fully understand.

Is "images/noimage.gif" a file? A path is specified, so it must be, right?

You could put it in the database (e.g. GID=0) and retrieve it before looking
for any other image then use it if no image exists.


Yes the noimage.gif is an image file, but when I am calling photo.asp it is
looking for binary data in return and not text. I don't know how to insert
a row with GID=0 and binary image data into SQL server. The existing data
is from a vendor.
 
M

McKirahan

MVM said:
[snip]

Yes the noimage.gif is an image file, but when I am calling photo.asp it is
looking for binary data in return and not text. I don't know how to insert
a row with GID=0 and binary image data into SQL server. The existing data
is from a vendor.

Perhaps you could retrieve the image via the FileSystemObject ...

But then I found this in the documentation:

"The FSO object model, which is contained in the Scripting type library
(Scrrun.dll), supports text file creation and manipulation through the
TextStream object. Although it does not yet support the creation or
manipulation of binary files, future support of binary files is planned."
 
M

MVM

McKirahan said:
MVM said:
[snip]

Yes the noimage.gif is an image file, but when I am calling photo.asp it is
looking for binary data in return and not text. I don't know how to insert
a row with GID=0 and binary image data into SQL server. The existing data
is from a vendor.

Perhaps you could retrieve the image via the FileSystemObject ...

But then I found this in the documentation:

"The FSO object model, which is contained in the Scripting type library
(Scrrun.dll), supports text file creation and manipulation through the
TextStream object. Although it does not yet support the creation or
manipulation of binary files, future support of binary files is planned."

I thought I would let you know how I got this working. I first run the
query on the database searching the photo table. If there are no images,
then I run the code for displaying the noimage.gif. If there is a matching
record then I query the database again and return the photo. Below is the
code:

If intRecordCount5 = 0 Then
strOutput = strOutput + "<img src='images/noimage.gif' width='300'
height='225'></td>"
Else
strOutput = strOutput + "<img src='photo.asp?GID=" & objRS("GID") & "'
width='300' height='225'></td>"
End If

Thanks for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top