Results 1 to 5 of 5

Thread: [2.0] Read and Write images from Database

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2000
    Location
    Cairo, Egypt
    Posts
    126

    [2.0] Read and Write images from Database

    I want to save an image from a picturebox in the form to the database and read it again from the database to the picturebox. I try to use [PictureBox.Image.Save(<MemoryStream>, PictureBox.Image.RawFormat)] but I got an error. How to do it?

  2. #2
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: [2.0] Read and Write images from Database

    What sort of database is it?

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [2.0] Read and Write images from Database

    Also, what is the exact code that you are using and what is the error?

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Dec 2000
    Location
    Cairo, Egypt
    Posts
    126

    Re: [2.0] Read and Write images from Database

    I use SQL database and this is the code I found in VS 2003
    Code:
            MemoryStream ms = new MemoryStream();
    
            PictureBox1.Image.Save(ms, PictureBox1.Image.RawFormat);
    
            byte[] arrImage = ms.GetBuffer();
    
            // Close the stream object to release the resource.
            ms.Close();
    It works good in VS 2003 but the same concept in VS 2005 make an error Message "A generic error occurred in GDI+."
    I don't want to make a binding controls to the database but I just want to save the picture from the picturebox to the field image in the database and retrieve it again later.

  5. #5
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: [2.0] Read and Write images from Database

    "PictureBox1.Image.RawFormat"
    I've got such problem once
    Try using another format, like JPeg or Bmp. I guess that fixed it
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

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