How to: Display Pictures from a Database in Windows Forms

In Windows applications, you can use the Data Sources Window to bind images in a database to appear in a PictureBox control.

Note

Any other controls that are available to your project that support data binding and can display images can be used in place of the PictureBox.

Items in the Data Sources window that are stored as byte arrays (pictures in a database are typically stored as byte arrays) have their control type set to None by default. Because byte arrays can contain anything from a simple array of bytes to the executable file of a large application, you must set the control for displaying byte-array columns based on your actual data. For columns that contain pictures, set that column's drop type to PictureBox from that item's control list. For more information, see How to: Set the Control to be Created when Dragging from the Data Sources Window.

The following procedure assumes that the Data Sources window is already populated with an item that is bound to your image. For more information, see How to: Connect to Data in a Database.

To bind pictures in a database to a PictureBox control

  1. In the Data Sources window, expand the desired table or object type to display its columns or properties.

  2. Select the column or property that contains your image data, and from its control list, choose PictureBox.

    Note

    Your form must be opened in the designer for the control drop-down lists to appear in the Data Sources window.

See Also

Tasks

How to: Add Custom Controls to the Data Sources Window

Concepts

What's New in Data

Displaying Data Overview

Other Resources

Data Walkthroughs

Getting Started with Data Access

Connecting to Data in Visual Studio

Preparing Your Application to Receive Data

Fetching Data into Your Application

Displaying Data on Forms in Windows Applications

Editing Data in Your Application

Validating Data

Saving Data