Save image to sql.

Hello, lately I have been triying to create a code to upload an image into my sql database from visual cobol 2012. I have done this in C# with 

byte[] image
object o = Clipboard.GetDataObject().GetData("Bitmap");
if (o != null)
{
pictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox.Image = (Image)o;
}

using (MemoryStream ms = new MemoryStream())
{
pictureBox.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
image = ms.ToArray();
}

Im not sure how I can do " pictureBox.Image = (Image)o;"  in visual cobol, since im stuck there I haven't tried to code the rest but I don't think that would be any problem.

How can I manage to do this task in visual cobol? 

Parents
  • Verified Answer

    I have used the attached method with succes a while ago (1 Gb of pictures)

    The ReadAllBytes does the read (very fast !!)

    Succes,

    Jan Vink

    -------------------------------------------------------------------------------------------------------------------

          01 inpmap-record   pic x(250) value 'C:\Pictures\image9.jpg'.

          01 input-document-data type System.Byte[].

            method-id  get-a-foto

          *>==================================

          *> Get complete image for insert

          *> inpmap-record contains the complete path\filename if the image

          *>==================================

               invoke type System.IO.File::ReadAllBytes(inpmap-record) RETURNING input-document-data.

          *> Test for errors with Try / Catch

          *> Now you can insert the image of the file (or word doc etc..) into the database

          *> Using MS-SQL-server insert statement to insert the image

          *>

          *> where the database field 'foto' is defined as :'[image] NULL,'

             set foto to input-document-data.

          *> Insert into statement

            end method.

Reply
  • Verified Answer

    I have used the attached method with succes a while ago (1 Gb of pictures)

    The ReadAllBytes does the read (very fast !!)

    Succes,

    Jan Vink

    -------------------------------------------------------------------------------------------------------------------

          01 inpmap-record   pic x(250) value 'C:\Pictures\image9.jpg'.

          01 input-document-data type System.Byte[].

            method-id  get-a-foto

          *>==================================

          *> Get complete image for insert

          *> inpmap-record contains the complete path\filename if the image

          *>==================================

               invoke type System.IO.File::ReadAllBytes(inpmap-record) RETURNING input-document-data.

          *> Test for errors with Try / Catch

          *> Now you can insert the image of the file (or word doc etc..) into the database

          *> Using MS-SQL-server insert statement to insert the image

          *>

          *> where the database field 'foto' is defined as :'[image] NULL,'

             set foto to input-document-data.

          *> Insert into statement

            end method.

Children
No Data