Using the SQL Server7.0 datatype image in VB6.0 (and ASP)

Using the SQL Server7.0 datatype image in VB6.0 (and ASP)

Post by Peter Roothan » Tue, 27 Jun 2000 04:00:00


Hello,

I'm looking for two procedures, one to move a graphical file (jpeg, gif,
...) into an image field in SQL Server7.0, and one to retrieve the image
from the database and put it back into a graphical file.

Thanks in advance,
Peter Roothans,
Belgium


 
 
 

Using the SQL Server7.0 datatype image in VB6.0 (and ASP)

Post by Pit » Tue, 27 Jun 2000 04:00:00


Hi Peter,

Maybe if you line out this code, it might be of some help.
sorry i havent got the time to line ite out myself....

regards, Leon

Private Const SCONNECT As String = "filedsn=YourDsn.dsn"   '
module-level static variable with the filedsn to your
database

Private Sub SavePicture()

Dim iFileHandle As Integer                                 '    Number of
image file to open
Dim rsRecordset as ADODB.Recordset             '  recordset to open
Dim sSQLString                                                   ' SQL
string
Dim lStartPosition As Long                                   'Startposition
in the image file for continue reading
Dim iChunkCounter As Integer                             'Counter for loop
Dim lChunkSize As Long                                      'Size of Full
Chunk
Dim lLastChunkSize As Long                                'Size of Last
Chunk
Dim iNumberOfWholeChunks As Integer              'Number of full chunks
Dim arrBuffer() As Byte                                         'byte array
to temporary store the bytes read from the image file.

   sSQLString = " SELECT ID_Image, Image FROM Images.       '

   Set rsRecordSet = New ADODB.Recordset
    rsRecordSet.Open sSQL, SCONNECT, adOpenDynamic, adLockOptimistic    '
Opening recordset

    iFileHandle = FreeFile
'finding free filehandle
    Open "c:\MyImage.jpg" For Binary As iFileHandle
'Opening image file

    lChunkSize = lGetChunckSize(LOF(iFileHandle)
'Determining full chunksize
    iNumberOfWholeChunks = lTotalSize \ lChunkSize
'Determining number of full chunks
    lLastChunkSize = lTotalSize Mod lChunkSize
'Determing size of last chunk

        ReDim arrBuffer(1 To lChunkSize)
'Redim Array to full chunksize
        lStartPosition = 0
'Reset startposition
        For iChunkCounter = 1 To iNumberOfWholeChunks
'startloop
        Get iFileHandle,lStartPosition, arrBuffer(lChunkSize)
'Filling byte array with chunk
        rsRecordset.Fields("Image").AppendChunk (arrBuffer())        'Saving
chunk
        lStartPosition = lStartPosition + lChunkSize
'Next position in file
       Next iChunkCounter

         ReDim arrBuffer(1 To lLastChunkSize)
'Redim byte array to size of last chunk
        Get iFileHandle,lStartPosition, arrBuffer(lLastChunkSize)
'Filling byte array with last chunk
        rsRecordset.Fields("Image").AppendChunk (arrBuffer())
'Saving last chunk
        Close iFileHandle
'Closing image file
        RsRecordset.Update
        'Updating recordset
         rsRecordset.Close
'Closing recordset
        Set rsRecordset = nothing

End Sub

Quote:

> > Private Function lGetChunckSize(ByVal lWholeSize As Long) As Long

> >     Select Case lWholeSize
> >         Case 0 To 100
> >             lGetChunckSize = 10
> >         Case 100 To 1024
> >             lGetChunckSize = 100
> >         Case 1024 To 8192
> >             lGetChunckSize = 1024
> >         Case 8192 To 32768
> >             lGetChunckSize = 4096
> >         Case Is > 32768
> >             lGetChunckSize = 8192
> >         Case Else
> >             MsgBox lWholeSize
> >     End Select

> > End Function

 Private Sub GetPicture(ByVal PriKey As Integer)

          Dim rsRecordset As ADODB.Recordset

Quote:> >     Dim arrBuffer() As Byte
> >     Dim sSQLString as string

           Dim sTempFile as string
            Dim iFileHandle as integer

sSQLString = " SELECT ID_Image, Image FROM Images WHERE ID_Image = " &
PriKey       '

   Set rsRecordSet = New ADODB.Recordset
    rsRecordSet.Open sSQL, SCONNECT, adOpenDynamic, adLockOptimistic    '
Opening recordset
    arrBuffer() =
rsRecordset.Fields("Image").GetChunk(rsRecordset.Fields("Image").ActualSize)
'getting all of the image into byte array
        sTempFile = App.Path & "\output.bin"

Quote:

> >     iFileHandle = FreeFile
> >     Open sTempFile For Binary As iFileHandle

'Opening temporary file
Quote:> >     Put iFileHandle, , arrBuffer()

'Writing byte array to temp file
Quote:> >     Close iFileHandle
'Closing tempfile

         Set imgImage.Picture = LoadPicture(sTempFile, , vbLPColor)    'Load
ing image into  image control
Quote:> >     Kill sTempFile

'Deleting temp file
           rsRecordset.close
            Set rsRecordset = nothing

End Sub



- Show quoted text -

> Hello,

> I'm looking for two procedures, one to move a graphical file (jpeg, gif,
> ...) into an image field in SQL Server7.0, and one to retrieve the image
> from the database and put it back into a graphical file.

> Thanks in advance,
> Peter Roothans,
> Belgium



 
 
 

1. Store image by using image datatype in SQL 7.0

Hi all,

     I have read the mail which the subject is HOW TO USE THE BINARY OR THE IMAGE
DATATYPE. I find the method which is provided by Neil Pike. Unfortunately I have
problems in getting the image from table. How can I get the image size or file
length in the table. I have used "GETCHUNK" method but I cannot locate the image
in the table.

Please help me to solve this problem

Regards,
CY

2. ORACLE DBAs, Richmond, VA

3. Help..Using VB6 Data Control to access MS SQL Server7 Database

4. I am new to PRO*C and need help.

5. Image datatype help for VB6/SQL7

6. modifying new tuple on insert in c trigger

7. GIF in image datatype, how to get it out with an ASP script

8. Btrieve for OS2

9. Image datatype, and storing images in SQL server

10. SQL Server7 linking to another SQL Server7 database.

11. Placing and Getting Image Files using Frontpage, ASP and SQL Server

12. Loading images into SQL using ASP

13. SQL Server7 linking to another SQL Server7 database.