Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pulling an Image from an SQL Database

Status
Not open for further replies.

AndyApp

Programmer
Dec 20, 2001
259
GB
After searching hi and low through Microsofts TechNet and their Knowledgebase and everything else I could find I am still struggling to pull an image from and SQL database.

I know that I can build the recordset and then simply set the image tag to pull the relevant image out but is their seriously no way to do it using InterDev's built in Design-Time Controls??

The reason I don't want to do it that way is that the page is already built using all InterDev's own controls and recordsets, I really don't want to be re-bulding the entire page just for the sake of some images.

Their MUST BE A WAY!! "Life is like a Ferrari, it goes to fast.
But that's ok, because you can't afford it anyway" - Jim Davis (Garfield)
 
I am not sure what you mean. You can set an image tag source to a file name, where the file name is stored in the database:
<IMG SRC=&quot;<%=rsMyRecordset(&quot;ImageLocation&quot;)%>&quot;>

Or do you want to do a similar thing, but for DTC button images? You would just specify the image source in code:
dtcButon.src = rsMyRecordset(&quot;ImageLocation&quot;)

You cannot include an image directly on a page - you need to specify the image source. The source, however, can be an ASP page - and can take parameters too.

This ASP page will need to set a header to say that the content is of type image (jpeg or gif or whatever). It then needs to pull the binary data for the image from the database (or a file, but this is more involved) and pump it out using Response.binaryWrite.

There is plenty of samples of this on the web. Here is an example that uses ADO to pull binary data from a file (you just need to alter it to pull data from your database column):

<%@ Language=VBScript %>
<%Option Explicit%>
<%
response.buffer = true
response.Expires = 0
response.ExpiresAbsolute = Now() - 1
response.addHeader &quot;pragma&quot;,&quot;no-cache&quot;
response.addHeader &quot;cache-control&quot;,&quot;private&quot;
Response.CacheControl = &quot;no-cache&quot;

dim sItem
dim sRoot
dim sType

sItem = request.QueryString(&quot;item&quot;) & &quot;&quot;

if sItem = &quot;&quot; then
response.write &quot;Cannot display item.&quot;
response.end
end if

sType = lcase(right(sItem, 3))

select case sType
case &quot;pdf&quot;
response.ContentType =&quot;application/pdf&quot;
case &quot;xls&quot; 'MICROSOFT EXCEL document
response.ContentType =&quot;application/x-excel&quot;
case &quot;doc&quot; 'MICROSOFT WORD document
response.ContentType =&quot;application/msword&quot;
case &quot;rtf&quot; 'RTF document
response.ContentType =&quot;application/rtf&quot;
case &quot;gif&quot; 'image
response.ContentType =&quot;image/gif&quot;
case &quot;jpg&quot;, &quot;jpeg&quot; 'movie
response.ContentType =&quot;image/jpeg&quot;
case &quot;tif&quot;, &quot;tiff&quot; 'TIFF images
response.ContentType =&quot;image/tiff&quot;
case &quot;ppt&quot; 'MICROSOFT POWERPOINT document
response.ContentType =&quot;application/ms-powerpoint&quot;
case &quot;zip&quot; 'ZIP document
response.ContentType =&quot;application/zip&quot;
case else
response.write &quot;Cannot display items of this type.&quot;
response.end
end select

'Add the following to force a 'Save-As' popup..
'Response.AddHeader &quot;Content-Disposition&quot;, &quot;filename=zzzz;&quot;

sRoot = Server.MapPath(sItem)

'Create a stream object
Dim objStream
Set objStream = Server.CreateObject(&quot;ADODB.Stream&quot;)

objStream.Type = adTypeBinary
objStream.Open
on error resume next
objStream.LoadFromFile (sRoot)
if Err.number = 0 then
'Open a binary file
on error goto 0
Response.BinaryWrite objStream.Read
'Clean up....
else
response.clear
response.write &quot;Cannot display item.&quot; & sRoot
end if
objStream.Close
Set objStream = Nothing
%> (Content Management)
 
Merlin,

What I was hoping is that I could just drag something from the 'Design-Time Controls' Panel and data bind it to the SQL Database to pull the image out.

If I use the <IMG SRC=&quot;<%=rsMyRecordset(&quot;ImageLocation&quot;)%>&quot;> I get &quot;Object doesn't support this property or method&quot; error.

My recordset is called 'rePayReceipt' the tables is called 'Signatories' and the column is 'Signature' and they are stored in Binary format.

Any idea? &quot;Life is like a Ferrari, it goes to fast.
But that's ok, because you can't afford it anyway&quot; - Jim Davis (Garfield)
 
MerlinB,

The ContextType and BinaryWrite method doesn't work for me. Visual FoxPro was used to insert the images into the database. They are not in raw format. They have OLE headers that VFP added. Is there anyway I can strip off the headers?

Also, is there a way to detect the type of the image (gif or jpg)?

Thanks in advance.
 
Save the image tag below . Load the picture on a web page using a recordset object .for example if the fieldname is &quot;PicturePath&quot; then on the browser use <%=rs(&quot;PicturePath&quot;)%> to load the picture


------------Here is the Tag

<IMG SRC=/INTRANET/CLIPART/Picture1.jpg style=&quot;HEIGHT: 137px; WIDTH: 127px&quot;>


-----------Here is part of the code to load the picture from the web browser

<table border=1>
<%do while not rs.EOF %>
<TR>
<td><%=rs(&quot;PicturePath&quot;)%></td>
<TD><%=rs(&quot;Description&quot;)%></TD></TR>

</table>


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top