visualizar una imagen de una b.d
Publicado por iratxe (13 intervenciones) el 21/10/2007 11:52:18
Hola a todos, estoy haciendo un prama con visual basic 6.0 y ado para visualizar imagenes de una base de datos acces97.
Alguien sabe como se visualizan las imagenes? esque yo no consigo que se me visualicen porque rs.Fields me retorna un null y no entiendo.
If IsNull(rs.Fields(Campo_Imagen).Value) Then
GoTo error_Function
End If)
El codigo que tengo es el siguiente:
Public Function Leer_Imagen(ADO_Connection As ADODB.Connection, _
sql As String, _
Campo_Imagen As String) As Picture
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
On Error GoTo error_Function
Set rs = New ADODB.Recordset
Dim Stream As ADODB.Stream
' Llena el recordset
rs.Open sql, ADO_Connection, adOpenKeyset, adLockOptimistic
' Si no hay registros sale de la función y retorna como _
resultado un valor Nothing, es decir ninguna imagen
If rs.RecordCount = 0 Then
Set Leer_Imagen = Nothing
rs.Close
Set rs = Nothing
Exit Function
End If
' Nuevo objeto Stream para poder leer el campo de imagen
Set Stream = New ADODB.Stream
' Especifica el tipo de datos ( binario )
Stream.Type = adTypeBinary
Stream.Open
' verifica con la función IsNull que el campo no tenga _
un valor Nulo ya que si no da error, en ese caso sale de la función
If IsNull(rs.Fields(Campo_Imagen).Value) Then
GoTo error_Function
End If
' Graba los datos en el objeto stream
Stream.Write rs.Fields(Campo_Imagen).Value
' este método graba un archivo temporal en disco _
( en el app.path que luego se elimina )
Stream.SaveToFile App.Path & "\temp", adSaveCreateOverWrite
' Retorna la imagen a la función
Set Leer_Imagen = LoadPicture(App.Path & "\temp")
' Elimina el archivo temporal
Kill App.Path & "\temp"
'Cierra el recordset y el objeto Stream
If rs.State = adStateOpen Then
rs.Close
End If
If Not rs Is Nothing Then
Set rs = Nothing
End If
If Stream.State = adStateOpen Then
Stream.Close
End If
If Not Stream Is Nothing Then
Set Stream = Nothing
End If
Exit Function
error_Function:
If Err.Number <> 0 Then
MsgBox CStr(Err) & " " & Error, vbExclamation
' elimina el temporal
If Len(Dir(App.Path & "\temp")) Then
Kill App.Path & "\temp"
End If
End If
End Function
Alguien sabe como se visualizan las imagenes? esque yo no consigo que se me visualicen porque rs.Fields me retorna un null y no entiendo.
If IsNull(rs.Fields(Campo_Imagen).Value) Then
GoTo error_Function
End If)
El codigo que tengo es el siguiente:
Public Function Leer_Imagen(ADO_Connection As ADODB.Connection, _
sql As String, _
Campo_Imagen As String) As Picture
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
On Error GoTo error_Function
Set rs = New ADODB.Recordset
Dim Stream As ADODB.Stream
' Llena el recordset
rs.Open sql, ADO_Connection, adOpenKeyset, adLockOptimistic
' Si no hay registros sale de la función y retorna como _
resultado un valor Nothing, es decir ninguna imagen
If rs.RecordCount = 0 Then
Set Leer_Imagen = Nothing
rs.Close
Set rs = Nothing
Exit Function
End If
' Nuevo objeto Stream para poder leer el campo de imagen
Set Stream = New ADODB.Stream
' Especifica el tipo de datos ( binario )
Stream.Type = adTypeBinary
Stream.Open
' verifica con la función IsNull que el campo no tenga _
un valor Nulo ya que si no da error, en ese caso sale de la función
If IsNull(rs.Fields(Campo_Imagen).Value) Then
GoTo error_Function
End If
' Graba los datos en el objeto stream
Stream.Write rs.Fields(Campo_Imagen).Value
' este método graba un archivo temporal en disco _
( en el app.path que luego se elimina )
Stream.SaveToFile App.Path & "\temp", adSaveCreateOverWrite
' Retorna la imagen a la función
Set Leer_Imagen = LoadPicture(App.Path & "\temp")
' Elimina el archivo temporal
Kill App.Path & "\temp"
'Cierra el recordset y el objeto Stream
If rs.State = adStateOpen Then
rs.Close
End If
If Not rs Is Nothing Then
Set rs = Nothing
End If
If Stream.State = adStateOpen Then
Stream.Close
End If
If Not Stream Is Nothing Then
Set Stream = Nothing
End If
Exit Function
error_Function:
If Err.Number <> 0 Then
MsgBox CStr(Err) & " " & Error, vbExclamation
' elimina el temporal
If Len(Dir(App.Path & "\temp")) Then
Kill App.Path & "\temp"
End If
End If
End Function
Valora esta pregunta


0