CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2001
    Posts
    5

    Inserting images into database

    i have a tiff format image which was saved from a kodak image edit control and i want to insert in a field in sqlserver database. can any one of you please find a solution for me

    and please also give solution how to retrieve it to the kodak image edit control

    thanks in advance


  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Inserting images into database

    'Try this

    Const MAX_PATH = 255
    private Const CHUNK_SIZE = 1000
    private Declare Function GetTempPath Lib "kernel32" _
    Alias "GetTempPathA" (byval nBufferLength as Long, _byval lpBuffer as string) as Long
    public Function SavePictureToDB(PictControl as Object, _
    RS as Object, FieldName as string) as Boolean

    'PURPOSE: SAVES PICTURE IN IMAGEBOX, PICTUREBOX, OR SIMILAR
    'CONTROL to RECORDSET RS IN FIELD NAME FIELDNAME
    'FIELD TYPE MUST BE binary (OLE OBJECT IN ACCESS)

    'SAMPLE USAGE
    'Dim sConn as string
    'Dim oConn as new ADODB.Connection
    'Dim oRs as new ADODB.Recordset''
    'sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyDb.MDB;Persist Security Info=false"'
    'oConn.Open sConn
    'oRs.Open "SELECT * FROM MYTABLE", oConn, adOpenKeyset, _
    adLockOptimistic
    'oRs.AddNew
    'SavePictureToDB Picture1, oRs, "MYFIELD"
    'oRs.Update
    'oRs.Close

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  3. #3
    Join Date
    Apr 2001
    Posts
    44

    Re: Inserting images into database

    Please show me where is SavePictureToDB ?



  4. #4
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Inserting images into database

    Sorry the code got truncated on its way. Here is another procedure to save pic
    in db

    The Appendchunk()method can be used to achievd this also, but the usage of streams is a cleaner method
    of coding.

    Public Function SavePictureToDB(RS As ADODB.Recordset, _
    sFileName As String)

    On Error GoTo procNoPicture
    Dim oPict As StdPicture

    Set oPict = LoadPicture(sFileName)

    'Exit Function if this is NOT a picture file
    If oPict Is Nothing Then
    MsgBox "Invalid Picture File!", vbOKOnly, "Oops!"
    SavePictureToDB = False
    GoTo procExitSub
    End If

    RS.AddNew


    Set strStream = New ADODB.Stream
    strStream.Type = adTypeBinary
    strStream.Open
    strStream.LoadFromFile sFileName
    RS.Fields("***YourImageField***").Value = strStream.Read

    Image1.Picture = LoadPicture(sFileName)
    SavePictureToDB = True

    procExitSub:
    Exit Function
    procNoPicture:
    SavePictureToDB = False
    GoTo procExitSub
    End Function



    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured