You need to display an image from a database in a Windows Forms control.
Read the image into a byte array and load it directly into a
PictureBox control with a
The sample code contains six event handlers:
Sets up the sample by filling a
DataTable within a
DataSet with the Employees table from the
Northwind sample database. The EmployeeID, LastName, and FirstName
fields are bound to
TextBox controls. The
BindingManagerBase is obtained for the Employees
table in the
DataSet, a handler is attached to
PositionChanged event, and that handler
is called to position the display on the first record.
PictureBox with the image for the
current record. This event is raised when the
Position property value changes.
The EmployeeID for the current record is obtained using the position
information in the
BindingManagerBase object. A
Connection object and
object are created and used to retrieve the Photo binary field for
the employee record into a
Byte array. A
MemoryStream object is created from the
Byte array. The static
FromStream( ) method of the
class is used to load the image into the
PictureBox from the
Sets the current record of the bound controls to the first record by
Position property of the
BindingManagerBase object to 0.