We recommend using Visual Studio 2017
This documentation is archived and is not being maintained.

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.