Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2003-01-24 : 09:18:23
|
| Sam writes "Hi, I have read other articles with relation to displaying images using SQL and ASP. Here is my scenario.I have 1 table with 3 columns ImageLoc <varchar> Product <char> and Availability <char>When a user makes a selection from the ASP site, i would like the record to be displayed (and the image based on the pathname in the ImageLoc field)The database side is done.. Can someone give me some sample ASP code to work with that will display the Image and it's associated record.Here is my code@LANGUAGE="VBSCRIPT" CODEPAGE="1252"<!--#include file="file:///C|/Documents%20and%20Settings/Admin/My%20Documents/test.asp" -->Dim bobjRSDim bobjRS_numRowsSet bobjRS = Server.CreateObject("ADODB.Recordset")bobjRS.ActiveConnection = MM_test_STRINGbobjRS.Source = "SELECT * FROM dbo.Inventory"bobjRS.CursorType = 0bobjRS.CursorLocation = 2bobjRS.LockType = 1bobjRS.Open()bobjRS_numRows = 0<html><head><title>Untitled Document</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body><A>=(bobjRS.Fields.Item("ImageLoc").Value) =(bobjRS.Fields.Item("ProductMake").Value) =(bobjRS.Fields.Item("ProductType").Value) =(bobjRS.Fields.Item("CostPrice").Value) </body></html>bobjRS.Close()Set bobjRS = Nothing" |
|
|
ValterBorges
Master Smack Fu Yak Hacker
1429 Posts |
Posted - 2003-01-24 : 09:30:17
|
| Create an asp page callit images.aspResponse.Buffer = TruestrFileName=Request("Image")strFilePath=server.mappath("/images/"&strFilename)Const adTypeBinary = 1Response.ClearSet objStream = Server.CreateObject("ADODB.Stream")objStream.OpenobjStream.Type = adTypeBinaryobjStream.LoadFromFile strFilePathstrFileType = "image/jpeg" ' change to the correct content type for your fileResponse.AddHeader "Content-Disposition", "attachment; filename=" & strFileNameResponse.AddHeader "Content-Length", strFileSizeResponse.Charset = "UTF-8"Response.ContentType = strFileTypeResponse.BinaryWrite objStream.ReadResponse.FlushobjStream.CloseSet objStream = NothingThen in you asp that you are creating from your recordset include an image tag with a src as such.<img src="images.asp?Image=Test.jpg">This should do it. |
 |
|
|
SamC
White Water Yakist
3467 Posts |
Posted - 2003-01-25 : 00:56:34
|
| I think this is a simpler approach for your problem than the one Valter proposes:First, I highly recommend writing a stored procedure and not executing a string as you have, but that's another story.Looks like you want to write all images in a recordset selected by "*"? You'll need to add a loop.Leaving your ADO as-is, here's what I'd do with the HTML in ASP.WITH bobjRS response.write "<IMG SRC=""" & .Fields.Item("ImageLoc").Value & ">" response.write "<br>Make: " & .Fields.Item("ProductMake").Value response.write "<br>Type" " & .Fields.Item("ProductType").Value response.write "<br>Item: " & .Fields.Item("CostPrice").ValueEND WITHThere's really nothing to writing an HTML <IMG> from ASP. I've used Valter's approach when I generated a graphic using a library, but for loading an existing filename it seems complex.SamC |
 |
|
|
|
|
|