What you can do is, for example, place a picture box on your form with a default image then use your File Dialog and have the user select an image file. Now here is the question I have, after the use selects the image from the file dialog does that image need to be automatically placed in the picture box?
Or, after the user selects a file, do they hit submit of some sort to write the image to a database THEN the picture box has an image associated with it?
If you look at the code for your form and, assume that you have added an image to the picturebox your code will look something like:
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictu re.ext")));
All its doing is casting the object to a type of System.Drawing.Image.
If, for example, you were to stream this file to disk as opposed to saving it to the database you could do something like this in code:
pictureBox1.Image = Image.FromFile("pic.jpg")
However, since you need to place this into a database you are going to have to write some GDI functionality that will pull the byte stream from SQL and then create an image object on the fly. (Depending on your skill set, GDI can be a bit of a challenge, but for what you need to do, it is relatively simplistic)
For example:
Bitmap bmpFile;
MemoryStream stmFile = new MemoryStream();
BinaryWriter objWriter = new BinaryWriter(stmFile);
objWriter.Write(dtImg.Rows[0][0]);
bmpFile = new Bitmap(stmFile);
I assume you pull back the data into a datatable and that the data sits at Row 0 Position 0
From there all you have to do is add it to your picture box.
hth
--Stole this from a moderator
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
|