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

    Update a picture into Sql Server database.

    In SQL Server, Northwind database, Categories table has a column "Picture", that column type is image. I think that all picture is update into data by binary type.

    But I don't know how to display that data into a real picture in VB form, And I also can't update a picture into database when I choose a picture from my application.
    Hope to hear from you soon.


  2. #2
    Join Date
    Feb 2000
    Posts
    440

    Re: Update a picture into Sql Server database.

    OK, one easy thing you could do is to save this to file using getChunk and then open it with LoadPicture().

    here is an example



    Dim sTempFile as string
    Dim iFileNum as Long
    Dim abBytes() as Byte
    Dim lFileLength as Long

    sTempFile = "c:\mypicture.jpg"

    ' Open your recordset here
    ' rs.Open "Select ...",cnn

    iFileNum = FreeFile
    Open sTempFile for binary as #iFileNum
    lFileLength = LenB(rs(FieldName))
    abBytes = rs(FieldName).GetChunk(lFileLength)
    Put #iFileNum, , abBytes()
    Close #iFileNum
    PictControl.Picture = LoadPicture(sTempFile)

    ' close your recordset here





    Hope this helps,
    I don't know if this is the best way,
    there may have another ways, you
    may try to explore the databound properties
    of picture control, but the above works for sure.



    Valery Iskarov Nikolov
    Software Dynamics

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