943,104 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 960
  • C# RSS
Mar 13th, 2010
0

Retrieve image from database

Expand Post »
Hi Experts
I m trying to retry images from database. My code is as below
C# Syntax (Toggle Plain Text)
  1. DataTable tab = obj.createtable("Select pics from picto");//obj is the class in which createtable(string query) is function which returns datatable according to query
  2.  
  3. byte[] ImgByte = (byte[])tab.Rows[0][0];
  4. FileStream fs = new FileStream("test.GIF", FileMode.Create);
  5. fs.Write(ImgByte, 0, ImgByte.Length);
  6. fs.Close();
  7. fs = null;
  8. pictureBox2.Image = Image.FromFile("test.GIF");

the last line give "out of memory " error.
Plz help me
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
ejazmusavi is offline Offline
42 posts
since Jun 2009
Mar 13th, 2010
0
Re: Retrieve image from database
>the last line give "out of memory " error.

Image file has invalid file-format.
Moderator
Reputation Points: 2134
Solved Threads: 1227
Posting Genius
adatapost is offline Offline
6,524 posts
since Oct 2008
Mar 13th, 2010
0
Re: Retrieve image from database
I have tried another way.
C# Syntax (Toggle Plain Text)
  1. DataTable tab = obj.createtable("Select pics from picto where id=1");
  2. //obj is a class in which createtable(string query) is a function which returns datatable of query
  3. byte[] ImgByte = (byte[])tab.Rows[0][0];
  4. MemoryStream fs = new MemoryStream(ImgByte);
  5. fs.Write(ImgByte, 0, ImgByte.Length);
  6. MessageBox.Show(ImgByte.Length.ToString());
  7. Bitmap bm = new Bitmap(fs);
  8. pictureBox2.Image = bm;
this gives "Parameter no valid " error
plz help me.
Reputation Points: 10
Solved Threads: 0
Light Poster
ejazmusavi is offline Offline
42 posts
since Jun 2009
Mar 13th, 2010
0
Re: Retrieve image from database
.NET throws OutOfMemoryException if it does not recognize the image format.
Moderator
Reputation Points: 2134
Solved Threads: 1227
Posting Genius
adatapost is offline Offline
6,524 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Remoting & Events
Next Thread in C# Forum Timeline: wsHttpBinding





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC