Database Reference
In-Depth Information
images = new Images();
if (images.GetRow())
{
this.textBoxl.Text = images.GetFilename();
this.pictureBoxl.Image = (Image)images.GetImage();
}
else
{
this.textBoxl.Text = "DONE";
this.pictureBoxl.Image = null;
}
You use the same if statement in the Next button's click event handler to look for the next image. If
none is found, you displayed the word DONE in the text box.
The image is returned from the database as an array of bytes. The PictureBox control's Image
property can be a Bitmap , Icon , or Metafile (all derived classes of Image ). Bitmap supports a variety of
formats including BMP, GIF, and JPEG. The getImage method, shown here, returns a Bitmap object:
public Bitmap GetImage()
{
MemoryStream ms = new MemoryStream(imageBytes);
Bitmap bmap = new Bitmap(ms);
return bmap;
}
Bitmap 's constructor doesn't accept a byte array, but it will accept a MemoryStream (which is
effectively an in-memory representation of a file), and MemoryStream has a constructor that accepts a byte
array. So, you create a memory stream from the byte array and then create a bitmap from the memory
stream.
Working with Text Data
Handling text is similar to handling images except for the data type used for the database column.
Try It: Loading Text Data from a File
To load text data from a file, follow these steps:
1. Select the Text and Binary Data project, right-click, and choose Add
Windows Form. From the opened dialog, make sure Windows Form is
selected, and rename Form1.cs to LoadText.cs ; click OK to add this form to the
Text and Binary Data project.
2. Select the LoadText form, and set the Size property's Width to 496 and Height
to 196.
3. Drag a TextBox control to the form, and position it toward the center of the
form. Select this TextBox control, navigate to the Properties window, and set
the following properties:
Set the Name property to txtLoadText.
 
Search WWH ::




Custom Search