Discussion Locked

Dynamic images in ASP & SQL

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi,
I'm working on a SQL-database driven web application in which I want to include dynamic images. I'm developing in Macromedia Dreamweaver UltraDev 4. My pages are connected to MS SQL Server 7.0
My question is in which format to put data in SQL Server so that I can retrieve this in ASP-pages.
Images are in JPG & GIF format.
Thanks very much,
CONIX Wim

3 replies

by bojidar alexandrov

For data of image you must use "image" data type.
Sample SQL Script
-----
CREATE TABLE [dbo].[images] (
[image_id] [int] IDENTITY (1, 1) NOT NULL ,
[image_data] [image] NULL ,
[image_type] [varchar] (100) NOT NULL
-----
Sample piece of code from real ASP
-----
Dim rsImage
Set rsImage = Server.CreateObject("ADODB.RecordSet")
rsImage.Open SelectImageQuery, dbConn,,, 1
if Err.number = 0 then
if not rsImage.EOF then

Response.ContentType = Trim(rsImage("image_type"))

DimBlockSize
BlockSize=4096

Dim FileLength
Dim NumBlocks
Dim LeftOver,i

FileLength = rsImage("image_data").ActualSize
NumBlocks = FileLength \ BlockSize
LeftOver = FileLength Mod BlockSize
if LeftOver>0 then
Response.BinaryWrite rsImage("image_data").GetChunk(LeftOver)
End If
For i = 1 To NumBlocks
Response.BinaryWrite rsImage("image_data").GetChunk(BlockSize)
Next

end if
rsImage.Close
end if
set rsImage = Nothing
CloseDBConnection
Response.End
-------
You must fully understand this and write one for your needs

This discussion is closed to new replies.