#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2006
    Posts
    3
    Rep Power
    0

    How to use blob field in VB6.0


    hi to all,

    i have been reseaching on how to store images in firebird database using the blob field, could anyone plz help me? tnx in advance
  2. #2
  3. Modding: Oracle MsSQL Firebird
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2001
    Location
    Outside US
    Posts
    8,527
    Rep Power
    539
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2006
    Posts
    3
    Rep Power
    0
    Originally Posted by pabloj
    There's a tutorial for mysql available on the net, Firebird is quite similar.
    I'll put up a specific example soon (or at least I hope so )
    i've test the example on mysql in firebird and it works, thanks
  6. #4
  7. Modding: Oracle MsSQL Firebird
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2001
    Location
    Outside US
    Posts
    8,527
    Rep Power
    539
  8. #5
  9. Modding: Oracle MsSQL Firebird
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2001
    Location
    Outside US
    Posts
    8,527
    Rep Power
    539
    I'm posting this here for future reference:
    vb Code:
    'CREATE CONNECTION OBJECT AND ASSIGN CONNECTION STRING
    Dim conn As ADODB.Connection
    Set conn = New ADODB.Connection
     
    conn.ConnectionString = "DRIVER={Firebird/Interbase(r) Driver};DBNAME=localhost:C:\Programmi\Firebird\Firebird_2_0\examples\empbuild\test.fdb;UID=SYSDBA;PW  D=masterkey"
     
    conn.CursorLocation = adUseClient
    conn.Open
     
    'OPEN RECORDSET FOR WRITING
    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
     
    Dim mystream As ADODB.Stream
    Set mystream = New ADODB.Stream
     
    mystream.Type = adTypeBinary
     
    rs.Open "SELECT * FROM files WHERE 1=0", conn, adOpenStatic, adLockOptimistic
     
    rs.AddNew
     
    mystream.Open
    mystream.LoadFromFile "c:\adaptor.jpg"
     
    rs!file_id = 1
    rs!file_name = "adaptor.jpg"
    rs!file_size = mystream.Size
    rs!file_blob = mystream.Read
    rs.Update
    mystream.Close
    rs.Close
     
    'OPEN RECORDSET TO READ BLOB
    rs.Open "Select * from files WHERE files.file_id = 1", conn
    mystream.Open
    mystream.Write rs!file_blob
    mystream.SaveToFile "c:\newimage.jpg", adSaveCreateOverWrite
    mystream.Close
    rs.Close
     
    'OPEN RECORDSET FOR UPDATE OF BLOB COLUMN
    rs.Open "Select * from files WHERE files.file_id = 1", conn, adOpenStatic, adLockOptimistic
    mystream.Open
    mystream.LoadFromFile "c:\adaptor.jpg"
    rs!file_blob = mystream.Read
    rs.Update
     
    mystream.Close
    rs.Close
     
    'OPEN RECORDSET TO READ UPDATED IMAGE
    rs.Open "Select * from files WHERE files.file_id = 1", conn
    mystream.Open
    mystream.Write rs!file_blob
    mystream.SaveToFile "c:\newupdatedimage.jpg", adSaveCreateOverWrite
     
    mystream.Close
    rs.Close
     
    conn.Close
     
    MsgBox "Success! Check your C:\ directory for newimage.jpg and newupdatedimage.jpg"
    Note that it's basically the same as the original article by Mike Hillyer
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2006
    Posts
    3
    Rep Power
    0
    Originally Posted by pabloj
    Would you mind posting here the Firebird version?
    Thanks
    here it is ..............

    Option Explicit

    Dim adoConn As New ADODB.Connection
    Dim mrsetRec As New ADODB.Recordset

    Private Sub Form_Load()
    With adoConn
    .ConnectionString = "Provider=MSDASQL;DSN=BLOBTest;UID=SYSDBA;PWD=masterkey;"
    .Open
    End With
    End Sub

    Private Sub Command1_Click()
    Dim strQuery As String
    Dim strFile As String
    Dim adoStream As New ADODB.Stream

    On Error GoTo lnError

    With CommonDialog1
    .CancelError = True
    .ShowOpen
    strFile = .FileName
    End With

    With adoStream
    .Type = adTypeBinary
    .Open
    .LoadFromFile strFile
    End With

    strQuery = "SELECT * FROM NEW_TABLE WHERE 1=0"
    With mrsetRec
    .Open strQuery, adoConn, adOpenStatic, adLockOptimistic
    .AddNew
    .Fields(0).Value = 1
    .Fields(1).Value = adoStream.Read
    .Update
    End With

    Exit Sub
    lnError:
    MsgBox Err.Description
    End Sub

    Private Sub Command2_Click()
    Dim strQuery As String
    Dim adoStream As New ADODB.Stream

    On Error GoTo lnError

    With adoStream
    .Type = adTypeBinary
    .Open
    End With

    strQuery = "SELECT * FROM NEW_TABLE"
    With mrsetRec
    .Open strQuery, adoConn
    adoStream.Write .Fields(1).Value
    adoStream.SaveToFile "C:\tmp.bmp", adSaveCreateOverWrite
    Image1.Picture = LoadPicture("C:\tmp.bmp")
    Kill "C:\tmp.bmp"
    End With

    Exit Sub
    lnError:
    MsgBox Err.Description
    End Sub

    Comments on this post

    • pabloj agrees

IMN logo majestic logo threadwatch logo seochat tools logo