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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the Binary Data from SQL

Status
Not open for further replies.

paragvshah

Programmer
Joined
Jan 11, 2001
Messages
109
Location
IN
Hi All,

I want to display an image stored in as "Image" Datatype in SQL. I am able to Insert the data in the table but while retreiving, it display the junk data.

I am pasting the code. Can any one help me out at what place i am wrong?

------------------------------------------

<%
Response.Buffer = True

Dim ID
ID = Request(&quot;ID&quot;)

If Len(ID) < 1 Then
ID = 7
End If

Dim rs
Set rs = Server.CreateObject(&quot;ADODB.Recordset&quot;)

rs.Open &quot;select [ImageContent], [ContentType] from PDAImages where ImageID = &quot; & ID, cn, 2, 4

If Not rs.EOF Then
Response.ContentType = rs(&quot;ContentType&quot;)

BlockSize = 4096
Set Field = rs(&quot;ImageContent&quot;)
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
End If

rs.Close
Set rs = Nothing %>

----------------------------------------------

Please help me out

Thanks

Parag
 
Storing images in a database is inefficient and causes lots of problems (as you've seen!). It is a much better idea to simply store the path to the image in the DB and store the actual image in a folder somewhere.

If you can change your DB design then I would strongly recommend you do so. --James
 
I am getting junk data on the page while displaying the image.

Parag
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top