Databases Reference
In-Depth Information
protected override void Dispose(bool disposing)
{
images.EndImages();
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
The image is returned from the database as an array of bytes. The PictureBox control
Image property can be a Bitmap , Icon , or Metafile (all derived classes of Image ). Bitmap sup-
ports a variety of formats including BMP, GIF, and JPG. 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 con-
structor 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 Out: Loading Text Data from a File
To load text data from a file, follow these steps:
1. Add a C# Console Application project named LoadText to the solution.
2. Rename Program.cs to LoadText.cs , and replace the code with that in Listing 18-4.
Search WWH ::




Custom Search