?
Solved

.JPG saved to SQL Anywhere DB

Posted on 1998-09-03
8
Medium Priority
?
449 Views
Last Modified: 2013-11-19
How do I get a .jpg image saved into a SQLA database, with out using third party bound controls? The column object is a blob datatype.
0
Comment
Question by:zaus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1432908
Here is some MS code

Dim Cn As New ADODB.Connection
Dim rsRead As New ADODB.Recordset
Dim rsWrite As New ADODB.Recordset
Dim strChunk As String
Dim Offset As Long
Dim Totalsize As Long
Dim ChunkSize As Long

Cn.Open "pubs", "sa"

rsRead.CursorType = adOpenStatic
rsRead.Open "SELECT pr_info FROM pub_info", Cn

rsWrite.CursorType = adOpenKeyset
rsWrite.LockType = adLockBatchOptimistic
rsWrite.Open "SELECT * FROM myBLOB", Cn

ChunkSize = 1000
Totalsize = rsRead("pr_info").ActualSize

Do WHILE Offset < Totalsize
    strChunk = rsRead("pr_info").GetChunk(ChunkSize)
    Offset = Offset + ChunkSize
    rsWrite("info").AppendChunk strChunk
Loop
rsWrite.UpdateBatch
rsWrite.Close
rsRead.Close
End Sub

The example reads pr_info long data from the pub_info table and inserts it into the myBLOB table. After the rsRead and rsWrite record sets are created, the size of the long data is stored in the Totalsize variable. In the WHILE loop, long data is inserted in chunks of 1000 bytes. The WHILE loop stops when more data than the original long data size is inserted. After the insertion is completed, the UpdateBatch method is used to commit the data.


0
 

Author Comment

by:zaus
ID: 1432909
a111a111a111

Your code looks as if you are only taking a blob from one record and transferring it into another record. This we have no problem doing.

What this program does is take a photo from a digital camera using a third party software and displays the photo in our program in a third party control which is bound to the database. We are then able to issue ID cards with the photo and also retain the photo in our database for future use. The problem is the third party control that binds to the database fails to update on the 36 update while using the program. The 36 photo will not update. It causes an invalid page fault in MFC40.dll. We took off the control and updated 104 photos using microsoft image control, but this saves to the databse as a .BMP and for space we need them to be saved as .jpegs. We are looking for a way to update to the SQLA database using code and our current connections through ODBC. Or our other solution is solving the page fault.

I will wait for further answers from you before I grade.
0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1432910
Sorry I am not able to answer this now.

Please regrade the Question.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:zaus
ID: 1432911
thank you for trying (a111)^3


0
 
LVL 14

Expert Comment

by:waty
ID: 1432912
Here is a function to save your BLOB to a disk file :

Sub GetFileFromDB(BinaryField As Field, szFileName As String)
    ' *** Will retrieve an entire Binary field and write it to disk ***
   
    Dim NumChunks    As Long
    Dim TotalSize    As Long
    Dim RemChunk     As Integer
    Dim CurSize      As Integer
    Dim nChunkSize   As Long
    Dim nI           As Integer
    Dim nFile        As Integer
    Dim CurChunk     As String
   
    nChunkSize = 32000    ' Set size of chunk.
   
    ' *** Get field size.
    TotalSize = BinaryField.FieldSize()
    NumChunks = TotalSize \ nChunkSize   ' Set number of chunks.
   
    ' *** Set number of remaining bytes.
    RemChunk = TotalSize Mod nChunkSize
   
    ' *** Set starting size of chunk.
    CurSize = nChunkSize
    nFile = FreeFile ' Get free file number.
   
    Open szFileName For Binary As #nFile  ' Open the file.
    For nI = 0 To NumChunks
       If nI = NumChunks Then CurSize = RemChunk
       CurChunk = BinaryField.GetChunk(nI * nChunkSize, CurSize)
       Put #nFile, , CurChunk   ' Write chunk to file.
    Next
    Close nFile

End Sub


0
 

Author Comment

by:zaus
ID: 1432913
I understand what you have done Watty, however it fails to work for our application. We want to bring in a photo from a SQLA database and write it into a control. We connect using a data control ( data1) and what we want to do is
variant=data1.recordset("photo_front").getchunk(0,32000)
read in this information then display it in our control, and use the append method to load the photo into the database. The recordset is being set by data1.recordsource=(select * from photo where ssn = '000000000'" then on this recordset we want to retrieve the photo_front into the control. using the previous code. Any more advise would be greatly appreciated, and points have been increased to 150
0
 
LVL 14

Expert Comment

by:waty
ID: 1432914
It is not possible to do it directly. There are so much things we would like to do, but sometime we have to imagine some tricks and work around :(
0
 

Accepted Solution

by:
jfayling earned 300 total points
ID: 1432915
I don't know if this is the same thing, but I use this function to copy gifs, and jpgs into a memo field of an access database.

just do the following

    just call ConvertFileToDatabase and store the return value into the database field.

Hope that helps



Function ConvertFileToDatabase(FileName As String) As String
'
'   Function Name:  ConvertFileToDatabase
'
'   Author:         Byte Information Technologies (Jason R. Fayling)
'                   jfayling@byte-infotech.com
'
'   Date:           4/98
'
'   Inputs:         FileName    =   Location of picture file to convert to a string
'
'   Outputs:        Picture in string format
'
'   Purpose:        Converts a picture file into a string
'
'   Called from:    
'
'   Functions used in this code:

On Error GoTo ConvertFileToDatabaseError

Dim NextFree As Integer
Dim Temp As String
Dim buffer As String

    Temp = String(1000, " ")       ' get 1000 bits per loop
    NextFree = FreeFile      ' set to next available file handler
    buffer = ""                  ' Used to store picture
   
    Open FileName For Binary As NextFree    ' open the picture
        While Not EOF(NextFree)
       
            Get #NextFree, , Temp        ' stores bits into Temp
            buffer = buffer + Temp          ' transfers to buffer
           
        Wend ' loop until all the bits in the picture have been
             'copied
    Close                                   ' close the picture
   
    ConvertFileToDatabase = Trim$(buffer)   ' return the picture
                                            'as a string
   
    Exit Function
   
ConvertFileToDatabaseError:
   
    MsgBox Str$(Err.Number) + ": " + Err.Description + " in " + Err.Source
    'Resume
   
End Function
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
In this Micro Tutorial viewers will learn the basic shortcuts and functions in InDesign.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question