Click here to Skip to main content
16,005,037 members
Home / Discussions / C#
   

C#

 
GeneralRe: Hide from Alt+Tab screen Pin
Muammar©15-Feb-07 7:18
Muammar©15-Feb-07 7:18 
AnswerRe: Hide from Alt+Tab screen Pin
Daniel Grunwald15-Feb-07 9:43
Daniel Grunwald15-Feb-07 9:43 
GeneralRe: Hide from Alt+Tab screen Pin
Ed.Poore15-Feb-07 14:54
Ed.Poore15-Feb-07 14:54 
AnswerRe: Hide from Alt+Tab screen Pin
Ed.Poore15-Feb-07 14:59
Ed.Poore15-Feb-07 14:59 
QuestionGood N-Tier book for Newbie Pin
allan.gagnon15-Feb-07 6:55
allan.gagnon15-Feb-07 6:55 
QuestionA low quality-like gradient Pin
sharpiesharpie15-Feb-07 6:48
sharpiesharpie15-Feb-07 6:48 
AnswerRe: A low quality-like gradient Pin
Insincere Dave15-Feb-07 9:54
Insincere Dave15-Feb-07 9:54 
QuestionDisplay image from SQL DB on to Picturebox In Windows Forms App Pin
bemahesh15-Feb-07 6:15
bemahesh15-Feb-07 6:15 
Hi,

I am trying to display an image from the sql 2000 database on to the picture box control on windows app (VS 2.0).

I am able to pull the image in to byte array. I also am able to put the byte array in to the Memory stream by writing it like stream.Write(image, 0, image.Length)

However, when i try to create a bitmap out of the memory stream it thorows an exception stating "parameter is not valid".

The second approach I tried was to use Image.FromStream(ms1) method, but it also says "parameter is not valid" when it tries to get the image from stream (memory stream).

The third approach i tried was writing to a temporary file stream and then read from file using Image.FromFile(strfn, true). This line gets an error stating "Out of memory".

Nothing seems to be working. Please shed some light if possible. All i want to do is display an image from sql db field(image field) on to picture box in windows application using C# 2.0

Please look at the code below for detail. The line in bold where I am getting my exceptions.


// Put user code to initialize the page here
MemoryStream stream = new MemoryStream();
SqlConnection connection = new SqlConnection(@"my connection string");
try
{
connection.Open();
SqlCommand command = new SqlCommand("select image from images Where EntryDate > '2/15/2007'", connection);
byte[] image = (byte[])command.ExecuteScalar();
stream.Write(image, 0, image.Length);

Bitmap bitmap = new Bitmap(stream);

/////testing 2
MemoryStream ms1 = new MemoryStream(image);
exceptionPictureBox.Image = Image.FromStream(ms1);

///testing 3
string strfn = Convert.ToString(DateTime.Now.ToFileTime());
FileStream fs = new FileStream(strfn, FileMode.CreateNew, FileAccess.Write);

fs.Write(image, 0, image.Length);
fs.Flush();
fs.Close();

exceptionPictureBox.Image = Image.FromFile(strfn, true);
/////testing 3



}
finally
{
connection.Close();
stream.Close();
}

Thanks
Needy

QuestionBitmap Overlay Advice Pin
BRShroyer15-Feb-07 5:41
BRShroyer15-Feb-07 5:41 
AnswerRe: Bitmap Overlay Advice Pin
Luc Pattyn15-Feb-07 9:45
sitebuilderLuc Pattyn15-Feb-07 9:45 
QuestionHelp with DataTable update Pin
Matthew Cuba15-Feb-07 5:23
Matthew Cuba15-Feb-07 5:23 
AnswerSolved Pin
Matthew Cuba15-Feb-07 8:49
Matthew Cuba15-Feb-07 8:49 
QuestionHow to: Broswse for directory through PropertyGrid Pin
SSMERK00715-Feb-07 3:58
SSMERK00715-Feb-07 3:58 
AnswerRe: How to: Broswse for directory through PropertyGrid Pin
JoeSharp15-Feb-07 4:05
JoeSharp15-Feb-07 4:05 
GeneralRe: How to: Broswse for directory through PropertyGrid Pin
SSMERK00715-Feb-07 4:57
SSMERK00715-Feb-07 4:57 
AnswerRe: How to: Browse for directory through PropertyGrid Pin
SSMERK00715-Feb-07 6:46
SSMERK00715-Feb-07 6:46 
QuestionSet & Get in a C# Class Pin
allan.gagnon15-Feb-07 3:57
allan.gagnon15-Feb-07 3:57 
AnswerRe: Set & Get in a C# Class Pin
Not Active15-Feb-07 4:07
mentorNot Active15-Feb-07 4:07 
GeneralRe: Set & Get in a C# Class Pin
Colin Angus Mackay15-Feb-07 4:13
Colin Angus Mackay15-Feb-07 4:13 
GeneralRe: Set & Get in a C# Class Pin
allan.gagnon15-Feb-07 4:32
allan.gagnon15-Feb-07 4:32 
GeneralRe: Set & Get in a C# Class Pin
Not Active15-Feb-07 4:33
mentorNot Active15-Feb-07 4:33 
AnswerRe: Set & Get in a C# Class Pin
Colin Angus Mackay15-Feb-07 4:12
Colin Angus Mackay15-Feb-07 4:12 
GeneralRe: Set & Get in a C# Class Pin
allan.gagnon15-Feb-07 4:26
allan.gagnon15-Feb-07 4:26 
GeneralRe: Set & Get in a C# Class Pin
allan.gagnon15-Feb-07 4:44
allan.gagnon15-Feb-07 4:44 
GeneralRe: Set & Get in a C# Class Pin
Colin Angus Mackay15-Feb-07 5:32
Colin Angus Mackay15-Feb-07 5:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.