General discussion

Locked

Pull image from SQL database to an ASP

By m.gallacher ·
SQL 7, Dreamweaver 4.
How do I retrieve an image from an SQL database and insert onto a Dreamweaver ASP? I am struggling with this and would like a *simple* solution, I should be so lucky!

This conversation is currently closed to new comments.

7 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Pull image from SQL database to an ASP

by Raffi_ In reply to Pull image from SQL data ...

You might want to just pull the image URL from the DB instead of the actual image.

Do you have a connection setup already to the DB?
Have you created the recordset in Dreamweaver?
Can you reliably retrieve the data for that recordset?
You SQL for retrieving just the image URL would look like:

SELECT table.imageurlfield
FROM table
WHERE condition1, condition2

You next need to 'wrap' the url in the proper ASP to write it to the client. The resulting code would look like:

<img src="<%=(Recordset1.Fields.Item("image").Value)%>"

Where recordset1 is the name you gave to the recordset created by the SQL query.

If this is totally greek or is too simplified please comment and I will go into greater detail.

Regards
Raffi_

Collapse -

Pull image from SQL database to an ASP

by m.gallacher In reply to Pull image from SQL data ...

Poster rated this answer

Collapse -

Pull image from SQL database to an ASP

by Raffi_ In reply to Pull image from SQL data ...

If you do not want to store just the URL you can use the same methodology. Have a BLOB field (BinaryLargeObject in most DB's) in the database to store your image. Then use the same methods I've outlined to extract the image.

Perhaps also you should be looking at DreamWeaver Ultradev as a tool. It is specifically made for doing exactly what you require. It also has all of the functionality (and more) of Dreamweaver.

www.macromedia.com

Regards
Raffi_

Collapse -

Pull image from SQL database to an ASP

by m.gallacher In reply to Pull image from SQL data ...

Poster rated this answer

Collapse -

Pull image from SQL database to an ASP

by Jay Eckles In reply to Pull image from SQL data ...

I'm doing something similar at work; here's what I've come up with:

1. If you're going to store the image in the database, then you'll have to have a separate ASP that is dedicated to serving the image(s). This is because an ASP can only return one content-type; if your main ASP is returning HTML, you can't just insert the binary image data in the middle of that HTML. It will be interpreted as gobledy-****. You'll have to dom something like
<img src="imagelookup.asp?image=<%=imageID%>">There's simply no way around that.

2. In your imagelookup.asp, retrieve the image from the database (that shouldn't be hard - if you need help with that, let me know). The tricky part is returning the image to the browser, because it's binary data. Here's some ASP to set the content-type correctly and return the image:
<% 'imagelookup.asp

'put your database code here to connect,
'query, and get the image
Dim conn
set conn = Server.CreateObject( "ADODB.Connection" )
conn.ConnectionString = 'insert proper driver string here
conn.Open

Dim query
'insert correct query
query = "SELECT image FROM table WHERE condition"

Dim resultset
set resultset = Server.CreateObject( "ADODB.Recordset" )
resultset.Open query, conn

Dim objImage
objImage = resultset.Fields.Item("image").Value

'if image type is jpeg, set content-type to
'"image/jpeg"; if gif, set to "image/gif"

Response.ContentType = "image/jpeg"
Response.BinaryWrite objImage

'or Response.BinaryWrite resultset.Fields.Item("image").Value if
'you don't want to store the image in a temp
'variable
%>

That's all there is to it. I know that you'd probably prefer not to have a separate ASP to retrieve the image, but honestly there is absolutely no other way to do it.

Good luck.

Jay Eckles
www.jayeckles.com

Collapse -

Pull image from SQL database to an ASP

by m.gallacher In reply to Pull image from SQL data ...

Poster rated this answer

Collapse -

Pull image from SQL database to an ASP

by m.gallacher In reply to Pull image from SQL data ...

This question was closed by the author

Back to Web Development Forum
7 total posts (Page 1 of 1)  

Related Discussions

Related Forums