Pictures in Access database

Results 1 to 3 of 3

Thread: Pictures in Access database

  1. #1
    Join Date
    Dec 1969

    Default Pictures in Access database

    How do I store a picture in a database?, and how do I call from ASP? Please any suggestions would be nice

  2. #2
    John D Guest

    Default RE: Pictures in Access database

    Hi Pete,<BR><BR>I&#039m not an expert on this, but what I did was create a naming convention for my pictures. In my case, it was an employee directory. Each employee had a photo, and an employee ID number that was already a field in the Access table. So rather than create a new field for the photo name, I would name the image 12345.jpg (where 12345 was the employee ID number). Then to load on a web page, I&#039d simply use the Image Src tag and call a variable within ASP, for example:<BR><BR>&#060;%<BR>Graphic = "&#060;img src=&#039" & objRS("ID") & ".jpg&#039 width=&#039 120&#039 height=&#039 160&#039 alt=&#039Associate Picture&#039&#062;"<BR>%&#062;<BR><BR>Then when it came time to display, <BR><BR>&#060;%Response.Write Graphic%&#062; is all I needed.<BR><BR>Probably a more elegent way to do this, but hopefully my tip will get you going in the right direction. (Image files were in the same directory as the ASP script in the above example)

  3. #3
    Leungas Guest

    Default RE: Pictures in Access database

    It would be easier (I mean a lot easier) to store the path in DB and the images at server.<BR><BR>But if you want to know how to do is a sample code<BR><BR>Public Sub SaveImage(ByVal SID As Integer, ByVal fn As String)<BR>&#039This determine how we control the size of data block that get write to DB<BR>Const Blocksize As Integer = 4096<BR><BR>&#039These are connection varibles<BR>Dim rs As ADODB.Recordset<BR>Dim Field As ADODB.Field<BR><BR>&#039These are tracking variables...<BR>Dim ln As Long<BR>Dim fp As Integer<BR>Dim block As Variant<BR><BR>On Error GoTo errorHandler<BR><BR> &#039To start and initialise all variables<BR> Set rs = RunSPReturnRS_RW("cp_GetPicture", Array("@StaffID", adInteger, 4, SID))<BR> Set Field = rs("Picture")<BR> <BR> &#039Determine block size and file size<BR> fp = OpenFile(fn)<BR> ln = GetLength(fp)<BR> block = GetBlock(fp, ln)<BR> CloseFile (fp)<BR> <BR> &#039Now do the writing to DB<BR> rs("picture").AppendChunk block<BR> rs.UpdateBatch<BR> rs.Close<BR> <BR> &#039The other stuff<BR> CtxSetComplete<BR> Exit Sub<BR><BR>errorHandler:<BR> CtxRaiseError g_modName, "SaveImage"<BR>End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts