Working with images

  • I work for the Health Ministry in Brazil, and I have a database (SQL Server 7.0) that will need to work with .jpg pictures associated with ceratin records.

    Which is the best way to do that ? I could use some guidance on the issue, what I know is that you have to use image datatype. I don´t have a clue on how to associate the .jpg file stored on disk with the column on the database.




  • This is an often a debated topic. Store the .jpgs in the filesystem and the path in the db or store the image in the db. I vote for the filesystem, but if you search this site for "images" you will find some other threads.

    Steve Jones

  • If you want to save/load your image in/from your SQL Server Database you will need to use the Stream object of ADO.

    Dim strStream As ADODB.Stream

    Dim rs As ADODB.RecordSet

    Dim cn As Connection

    ' This is how to save

    Set strStream = New ADODB.Stream

    strStream.Type = adTypeBinary


    strStream.LoadFromFile sFileName

    rs.Fields("imgImage").Value = strStream.Read

    ' This is how to load

    Set strStream = New ADODB.Stream

    strStream.Type = adTypeBinary


    strStream.Write rs.Fields("ImgImage").Value

    strStream.SaveToFile "C:\Temp.bmp", adSaveCreateOverWrite

    Image1.Picture = LoadPicture("C:\Temp.bmp")

    Kill ("C:\Temp.bmp")

    This is working with jpeg, gif, bitmap and more.

    Have fun,


  • Thanks guys I´ll try it out. But now that we are at it, can I use a normal query to fetch the image once it´s saved, or do I have to do some other trick ??? I mean the only way to fetch the data is using the stream object ???


    Edited by - Jammer_BR on 04/02/2002 7:35:04 PM


  • You can still return it as part of an ADO recordset, but then you have to use the "chunk" methods to write it out to disk. Depends on what you're doing. If you're using ASP the response object supports the IStream interface, you can push your blob directly out the port without having to write it to disk (if that makes sense in your situation anyway!). Stream isn't limited to blobs either, you can use it on disk files.


Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply