Insert Image into SQL Server

Example requests & Code samples for GdPicture Toolkits.
Post Reply
hwoodstrom
Posts: 1
Joined: Mon Mar 17, 2008 4:39 am

Insert Image into SQL Server

Post by hwoodstrom » Tue Aug 25, 2009 5:29 pm

I am looking for a code sample that inserts an image in a Sql Server database and a separate routine that extracts it from the database and displays it. My best guess is that this needs to be done with a byte array, but historically my guesses have a poor track record.

Do you have a code sample in VB6?

shriniv
Posts: 2
Joined: Thu Mar 11, 2010 12:44 pm

Re: Insert Image into SQL Server

Post by shriniv » Thu Mar 11, 2010 2:45 pm

The following code works with MS-Access and hopefully should work with SQL Server too. Here, rsimg is the recordset having the image stored in an "OLE Object" type column "docimage".

Code: Select all

'---read image from database
Dim arbyte() as byte
arbyte = rsimg.Fields("docimage").GetChunk(LenB(rsimg.Fields("docimage")))     'get image & store in byte
GdViewer1.DisplayFromByteArray (arbyte())         'display image in viewer
Erase arbyte
rsimg.Close

'---insert image into database
    Call Imaging1.SaveAsByteArray(arbyte, 0, "tif")              'save scanned image into byte
    With rsimg              'recordset
        .AddNew
        .Fields("docimage").AppendChunk (arbyte())
        .Update
        MsgBox "Page Saved"
    End With


kerrymanam
Posts: 1
Joined: Sat Nov 28, 2015 8:10 am

Re: Insert Image into SQL Server

Post by kerrymanam » Sat Nov 28, 2015 8:11 am

More about....Insert Image into database

Kerry

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests