How to upload Image from client into SQL Server 7.0

I would like to ask the Expert a question that i want to make an Client/Server APP in VB6 in order to saving my picture from client into SQL Server 7.0 database . I have known the main method is using ADO (appendchunk) but please give a clear example already rung well .

Thank you very much in advance
Who is Participating?
sidcapConnect With a Mentor Commented:

Just go at

Hope this helps, SIDCAP.
Private Function GetRandomFileName(sDirTarget As String, _
                                   sPrefix As String, _
                                   sExtention As String) As String

'Generates a unique temp file name for the specified directory
'with the specified extention
On Error Resume Next
Dim fs As FileSystemObject   ' **** requires filesystem object
Dim sFName As String
Dim iRnd As Long
Dim iUpperBound As Long, iLowerbound As Long


iUpperBound = 99
iLowerbound = 0
iRnd = Int((iUpperBound - iLowerbound + 1) * Rnd + iLowerbound)

sFName = CStr(iRnd) + CStr(DatePart("d", Now())) _
                    + CStr(DatePart("h", Now())) _
                    + CStr(DatePart("n", Now()))

sFName = sPrefix + sFName + "." + sExtention

Set fs = New FileSystemObject

If Not fs.FileExists(sDirTarget + "\" + sFName) Then
    GetRandomFileName = sDirTarget + sFName
    Exit Function
End If

End Function

Public Function CopyImageField(fld As ADODB.Field, _
                               fldTO As ADODB.Field)

'This function takes the source field image and copies it
'into the destination field.
'The function first saves the image in the source field to a
'temp file on disc. Then reads this temp file into
'the destination field.
'The temp file is then deleted
On Error Resume Next

Dim iFieldSize  As Long
Dim varChunk    As Variant
Dim baData()    As Byte
Dim iOffset     As Long
Dim sFName      As String
Dim iFileNum    As Long
Dim cnt         As Long
Dim z()         As Byte

Const CONCHUNKSIZE As Long = 16384

Dim iChunks As Long
Dim iFragmentSize As Long
    'Get a unique random filename
    sFName = GetRandomFileName(App.Path, "pic", "tmp")
    'Open a file to output the data to
    iFileNum = FreeFile
    Open sFName For Binary Access Write Lock Write As iFileNum
    'Copy the logo to a variable in chunks.
    iFieldSize = fld.ActualSize
    iChunks = iFieldSize / CONCHUNKSIZE
    iFragmentSize = iFieldSize Mod CONCHUNKSIZE
    If iFragmentSize > 0 Then
' if there is a frag then write it first, else just use chunk
        ReDim baData(iFragmentSize)
        baData() = fld.GetChunk(iFragmentSize)
        Put iFileNum, , baData()
    End If
    'Fragment added; Now write rest of chunks
    ReDim baData(CONCHUNKSIZE)
    For cnt = 1 To iChunks
        baData() = fld.GetChunk(CONCHUNKSIZE)
        Put iFileNum, , baData
    Next cnt
    'Close file
    Close iFileNum
    'Now we have the file on disk Load the pic from
    'the temp file into the other field
    Open sFName For Binary Access Read As #1
    ReDim z(FileLen(sFName))
    Get #1, , z()
    fldTO.AppendChunk z
    Close #1
    'Delete the file
    Kill (sFName)
End Function

lethanhhaiAuthor Commented:
Thank you very much
Can you give me your email address
All Courses

From novice to tech pro — start learning today.