How do i store OLE Object (JPG) file to database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mfozdar_mca
    New Member
    • Jul 2006
    • 2

    How do i store OLE Object (JPG) file to database

    Dear sir

    I m Software Engineer in Software co.


    My question is how do i Store OLE Object (JPG) file to database
    AppendChunk

    plz Help me
    Last edited by Niheel; Jul 6 '06, 02:37 PM.
  • neonk
    New Member
    • Jul 2006
    • 4

    #2
    Pass the OLE Picture Object and the ADO Database field to the following code. It's not pretty since it uses an intermediate Windows File, but it is the shortest piece of code I know. There are other methods using In Memory files, etc.

    To be honest I use the LEAD Tools Image Object that has a SAVE command.

    Neon K.


    Code:
     
    Public Sub WriteImage(ByRef pPict As StdPicture, ByRef pField As ADODB.Field)
      
    On Error Resume Next
     
    Dim strStream As New ADODB.Stream
     
    strStream.Type = adTypeBinary
    strStream.Open
    Call SavePicture(pPict, "TempTemp.bmp")
    strStream.LoadFromFile ("TempTemp.bmp")
    pField.Value = strStream.Read
    Kill "TempTemp.bmp"
    strStream.Close
     
    End Sub
    Last edited by Niheel; Jul 6 '06, 02:37 PM.

    Comment

    • sashi
      Recognized Expert Top Contributor
      • Jun 2006
      • 1749

      #3
      Hi there,

      below are some sample to store and to retrieve images from and to BLOB field.. give it a try..

      retrieve from BLOB field
      Code:
      Public Sub getBLOB(RS As ADODB.Recordset, Field As String, Des As String)
          Dim lngFieldSize As Long
          Dim fileBytes() As Byte
          Dim intFileHandle As Integer
      
          intFileHandle = FreeFile
         
          lngFieldSize = RS(Field).ActualSize
          If lngFieldSize > 0 Then
              fileBytes = RS(Field).GetChunk(lngFieldSize)
              Open Des For Binary As intFileHandle
                  Put intFileHandle, , fileBytes
              Close intFileHandle
          End If
      End Sub
      store to BLOB field
      Code:
      Public Sub setBLOB(RS As ADODB.Recordset, Field As String, Source As String)
          Dim fileBytes() As Byte
          Dim intFileHandle As Integer
      
          intFileHandle = FreeFile
      
          Open Source For Binary As intFileHandle
              fileBytes = InputB(LOF(intFileHandle) - 1, intFileHandle)
              RS(Field).AppendChunk fileBytes
          Close intFileHandle
      End Sub
      sample usage
      Code:
      setBLOB myRecordSet, "FileField", "c:\myfile.gif" ' Places file into database
      
      getBLOB myRecordSet, "FileField", "c:\myfile_extracted_from_database.gif"
      good luck my fren.. :)

      Comment

      • Skiran
        New Member
        • Oct 2006
        • 5

        #4
        Originally posted by sashi
        Hi there,

        below are some sample to store and to retrieve images from and to BLOB field.. give it a try..

        retrieve from BLOB field
        Code:
        Public Sub getBLOB(RS As ADODB.Recordset, Field As String, Des As String)
            Dim lngFieldSize As Long
            Dim fileBytes() As Byte
            Dim intFileHandle As Integer
        
            intFileHandle = FreeFile
           
            lngFieldSize = RS(Field).ActualSize
            If lngFieldSize > 0 Then
                fileBytes = RS(Field).GetChunk(lngFieldSize)
                Open Des For Binary As intFileHandle
                    Put intFileHandle, , fileBytes
                Close intFileHandle
            End If
        End Sub
        store to BLOB field
        Code:
        Public Sub setBLOB(RS As ADODB.Recordset, Field As String, Source As String)
            Dim fileBytes() As Byte
            Dim intFileHandle As Integer
        
            intFileHandle = FreeFile
        
            Open Source For Binary As intFileHandle
                fileBytes = InputB(LOF(intFileHandle) - 1, intFileHandle)
                RS(Field).AppendChunk fileBytes
            Close intFileHandle
        End Sub
        sample usage
        Code:
        setBLOB myRecordSet, "FileField", "c:\myfile.gif" ' Places file into database
        
        getBLOB myRecordSet, "FileField", "c:\myfile_extracted_from_database.gif"
        good luck my fren.. :)
        Is there any other method to do this?
        because after using this code it stores image as Long binary data. If you do the same With using MsAccess's form, it stores as Bitmap file. If we are handling Big database, then above example will make any differance to speed of accessing database?
        Plz reply waiting

        Comment

        • sashi
          Recognized Expert Top Contributor
          • Jun 2006
          • 1749

          #5
          Hi there,

          Another option will be converting BMP to JPG format respectively, take a look at below attached link, hope it helps. Good luck & take care.



          Originally posted by Skiran
          Is there any other method to do this?
          because after using this code it stores image as Long binary data. If you do the same With using MsAccess's form, it stores as Bitmap file. If we are handling Big database, then above example will make any differance to speed of accessing database?
          Plz reply waiting

          Comment

          • adnan amin
            New Member
            • Jan 2007
            • 8

            #6
            im also looking and still in progress of implementation "How do i store OLE Object (JPG) file to database( MS-ACCESS and SQL SERVEr2000) for my recent project..as soon as i will provide whole source code.in .ZIP format

            take care
            from geoamins.uni.cc

            Comment

            • ikebiz
              New Member
              • Jan 2008
              • 1

              #7
              hi co-scrpiters

              would you send me a running visual basic code for uploading and retrieving images from mysql database?

              here is my email address mil id removed
              please....

              because i tried so many codes that i have seen over the net but none of them will run... i think there something maybe on my code that i have to refresh..
              please send it to me... it will be very much appreciated...
              thnx all and god bless us all scripters...

              ikebiz...
              Last edited by debasisdas; Jan 30 '08, 08:47 AM. Reason: removed mail id

              Comment

              • debasisdas
                Recognized Expert Expert
                • Dec 2006
                • 8119

                #8
                Please find related discussions here and here .

                Comment

                Working...