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!

Displaying an image from a database 1

Status
Not open for further replies.

apex82

Programmer
Mar 2, 2009
127
GB
I am using a sql database and storing images on there.

Logos
Logo_ID | Logo data

I appear to be able to upload as the column is showing <Binary data>

My problem is I am not able to view the images.

If I wanted to view them in a list, I would have expected something like this?

Code:
<%
	sql = "SELECT * FROM Logos ORDER BY [Logo_ID] ASC;"

	Set rs = obj_CN.Execute(sql)
		
	While Not rs.EOF

  		Response.ContentType = "image/jpeg"
   		Response.BinaryWrite rs("Logo data").value

	    rs.MoveNext
	Wend
%>

Can anyone help?

Thanks.
 
Step 1: write a script like this

Showlogo.asp:
Code:
   <%
   Response.Expires = 0
   Response.Buffer = TRUE
   Response.Clear
   Response.ContentType = "image/gif"

   Set conn = Server.CreateObject("ADODB.Connection")
   conn.Open "(your connection string)"
   Set rs = conn.Execute("SELECT * FROM Logos WHERE Logo_id = 1") ' Normally you construct this 
   Response.BinaryWrite rs("logo data")
   Response.End
 %>


and actually show it like this:
Test.asp:
Code:
   <IMG SRC="showlogo.asp">



 
Thanks!

I made a couple of tweaks and that worked great.

Code:
<%
   Response.Expires = 0
   Response.Buffer = TRUE
   Response.Clear
   Response.ContentType = "image/jpeg"

   Set conn = Server.CreateObject("ADODB.Connection")
  
   conn.Open "connection string"
 
   SQL = "SELECT * FROM [Logos] WHERE Logo_ID =1;"
   
   Set rs = obj_CN.Execute(SQL)
   
   Response.BinaryWrite rs("Logo data")
   Response.End
%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top