
|
email this FAQ to a colleague
Q:
What's the simplest way to pull images out of a SQL Server database using an .asp file?
A:
While it is difficult to insert the image data directly inline, one workaround is to call a wrapper .asp file that retrieves the image and presents it to the calling .asp as a standard image source (in other words, in the form <IMG SRC="x"> ).
In the main file, use a statement such as the following:
<IMG SRC=gifwrap.asp?ID=<%=ImageID%>>
NOTE: The ImageID parameter is used as an index into the SQL image database.
And here is the gifwrap.asp file that retrieves the image from the database and dresses it up as a standard image source:
<%
dim ImageID
dim Image
ImageID = request.querystring("ID")
if ImageID <> "" then
set Connection = server.createobject("ADODB.Connection")
Connection.Open "DatabaseDSN", "UserName", "Password"
set Result = server.createobject("ADODB.Recordset")
sql = "SELECT ImageData FROM Images WHERE ImageID=" & ImageID
Result.Open sql, Connection, adOpenKeyset
if not (Result.eof and Result.bof) then
Image = Result("ImageData").GetChunk(1024000)
Response.ContentType = "image/gif"
Response.BinaryWrite Image
else
Response.Write "ID '" & ImageID & "' not found in DB."
end if
Result.Close
Connection.Close
else
Response.Write "ID is blank "
end if
Response.End
%>
- Wayne Berry
|
Articles
|
|
|
|
|
Jul 31, 1997 - Creating a Category Site with ASP
|
|
|
In this issue 15 Seconds implements a catalog site that is build with Active Server pages and SQL Server. Along with the implementation there is source code and a discussion of the advantages and disadvantages of creating a catalog site that gets its content from a database. Included are pages for displaying products, creating a menu page, category page, and running a search across a database.
[Read This Article] [Top]
|
|
|
|
Apr 22, 1997 - Active Server Components with VS 5.0
|
|
|
A rewrite of part one of a four-part series on Active Server objects. A simple example of creating a Active Server Component in Visual Studio 5.0 using the Active Template Library 2.0. The example component retrieves the user's cookie, if not available issues a new 128-bit cookie. Included in the issue is the source code and step by step instructions. This issue has been rewritten to illustrate the use of Visual Studio 5.0 and ATL 2.0 in writing Active Server Components.
[Read This Article] [Top]
|
|
|
|
Apr 6, 1997 - Creating a List Server with ASP
|
|
|
This issue describes how to make a list server using Active Server, SQL Server, and Stephen Genusa's ASPMail Component. Included are source and instructions for adding the user to the list from a Active Server page, removing the user from the list via a Active Server page, and sending mail to the whole list.
[Read This Article] [Top]
|
|
|
|
Jan 24, 1997 - Simple ASP Chat
|
|
|
This 15 Seconds' issue contains source code and step by step instructions for creating a chat session using Active Server pages, HTML and a standard web browser. Also demonstrated is writing and reading of a file with an Active Server page.
[Read This Article] [Top]
|
|
|