Discussion Locked

Inserting Images in MS-SQL Server 7.0

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
How do I insert images in SQL Server 7.0? The SQL Books Online does not give me an apt answer. Would someone kindly help me out?

5 replies

by lwe

You can find an example in Books Online under the title "Using Long Data Types". The example gives the code needed to add an image to a table in the pubs database.

by tdavenport

Images in a DB have various pros and cons but it is easy enough to do.

ID = Request.QueryString("ID")
BlockSize = 4096
Response.ContentType = "image/JPEG"
strQuery = "SELECT * FROM Blob WHERE Blob_ID = " & ID
Set oRS = oConn.Execute(strQuery) 'oConn is a Session level object
oRS.MoveFirst
Set Field = oRS("Blob")
FileLength = Field.ActualSize
NumBlocks = FileLength \ BlockSize
LeftOver = FileLength Mod BlockSize
Response.BinaryWrite Field.GetChunk(LeftOver)
For intLoop = 1 To NumBlocks
Response.BinaryWrite Field.GetChunk(BlockSize)
Next
oRS.Close

You can find complete information on this subject at MSDN.Microsoft.com search for image and SQL

This discussion is closed to new replies.