How to: Bind Controls to Pictures from a Database

You can use the Data Sources window to bind an image in a database to a control in your application. For example, you can bind an image to an Image control in a WPF application, or to a PictureBox control in a Windows Forms applications.

Pictures in a database are typically stored as byte arrays. Items in the Data Sources window that are 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. To create a data-bound control for a byte array item in the Data Sources window that represents an image, you must select the control to create.

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 a picture in a database to a control

  1. Make sure that the design surface you want to add the control to is open in the WPF Designer or the Windows Forms Designer.

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

  3. Select the column or property that contains your image data, and select one of the following controls from its drop-down control list:

    • If the WPF designer is open, select Image.

    • If the Windows Forms designer is open, select PictureBox.

    • Alternatively, you can select a different control that supports data binding and that can display images. If the control that you want to use is not in the list of available controls, you can add it the list and then select it. For more information, see How to: Add Custom Controls to the Data Sources Window.

See Also

Tasks

How to: Set the Control to be Created when Dragging from the Data Sources Window

How to: Add Custom Controls to the Data Sources Window

Reference

Data Sources Window

Concepts

Binding Windows Forms Controls to Data in Visual Studio

Preparing Your Application to Receive Data

Fetching Data into Your Application

Binding Controls to Data in Visual Studio

Editing Data in Your Application

Validating Data

Saving Data

Other Resources

Data Walkthroughs

Overview of Data Applications in Visual Studio

Connecting to Data in Visual Studio