Resumen Guardar Imagenes en Base de Datos (RDO)

Hola, aqui te mando un ejemplo para grabar imagenes en Access. Solamente que yo utilizo para esto RDO, no ADO. Puedes encontrarte un ejemplo si buscas AppendChunk o GetChunk de la ayuda de VB.

Rutina paraa cargar una imagen:

Private Function CargarFoto(pRS As rdoResultset, psFieldName As String, picFoto As PictureBox) As Boolean

   ' Se carga la imagen a un archivo temporal
   iDataFile = FreeFile
   Open PictureFileName For Binary Access Write As iDataFile
   iF1 = pRS(psFieldName).ColumnSize
   If iF1 = 0 Then
      Close iDataFile
      CargarFoto = False
      Exit Function
   End If
   iChunks = iF1 \ ChunkSize
   iFragment = iF1 Mod ChunkSize
   ReDim bChunk(iFragment)
   bChunk() = pRS(psFieldName).GetChunk(iFragment)
   Put iDataFile, , bChunk()
   For cI = 1 To iChunks
      ReDim bChunk(ChunkSize)
      bChunk() = pRS(psFieldName).GetChunk(ChunkSize)
      Put iDataFile, , bChunk()
   Next cI
   Close iDataFile

   ' Se carga la imagen al PictureBox
   picFoto.Picture = LoadPicture(PictureFileName)

   ' Se borra archivo temporal
   On Error Resume Next
   If Len(Dir$(PictureFileName)) Then
      Kill PictureFileName
   End If
   Err = 0

   CargarFoto = True

End Function

Rutina para grabar la imagen:

Private Function GuardarFoto(pRS As rdoResultset, psFieldName As String, picFoto As PictureBox) As Boolean

   ' Se guarda el PictureBox a un archivo temporal
   If picFoto.Picture = 0 Then
      GuardarFoto = False
      Exit Function
   End If
   SavePicture picFoto.Picture, PictureFileName

   ' Leer el archivo y guardarlo en la BD
   iDataFile = FreeFile
   Open PictureFileName For Binary Access Read As iDataFile
   iF1 = LOF(iDataFile) ' Longitud de los datos en el archivo
   If iF1 = 0 Then
      Close iDataFile
      GuardarFoto = False
      Exit Function
   End If
   iChunks = iF1 \ ChunkSize
   iFragment = iF1 Mod ChunkSize
   pRS(psFieldName).AppendChunk Null
   ReDim bChunk(iFragment)
   Get iDataFile, , bChunk()
   pRS(psFieldName).AppendChunk bChunk()
   ReDim bChunk(ChunkSize)
   For cI = 1 To iChunks
      Get iDataFile, , bChunk()
      pRS(psFieldName).AppendChunk bChunk()
   Next cI
   Close iDataFile

   ' Se borra archivo temporal
   On Error Resume Next
   If Len(Dir$(PictureFileName)) Then
      Kill PictureFileName
   End If
   Err = 0
   GuardarFoto = True

End Function

Espero te sirva.

Lic. Daniel Quintero
Kinethic Software
Tel. 5687-8384
e-mail:
dqr69@youvegotmail.net
dqr69@yahoo.com
dqr69@hotmail.com
¡SALUDOS DESDE LA CIUDAD DE MÉXICO!



Resumen Resumen

Visual Basic Página de Visual Basic

Página principal Página principal

www.jrubi.com