In this article we will see how to store and retrieve images from a SQL Server Database into a Data Grid in WPF using Data Binding. I am creating the database using the code first approach. Now we will look into the System Requirements.
System Requirements
The following are the System Requirements:
- Microsoft Visual Studio 2010.
- SQL Server 2008 R2.
Now we will look into the design part and it is shown below:
I have used a class named "ImageClass" and its definition is shown below.
public class ImageClass
{
public int Id { get; set; }
public string ImagePath { get; set; }
public byte[] ImageInBytes { get; set; }
}
In the preceding class, the "Id" property is the primary key, the "ImagePath" property will be the path of the image from the system that you will browse to and the "ImageToByte" property will store the image in the form of an array of bytes.
The XAML code for binding the data grid is shown below.
<DataGrid AutoGenerateColumns="False" Height="248" HorizontalScrollBarVisibility="Auto" HorizontalAlignment="Left" Margin="94,153,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="399" Background="#FFFFE2E2" >
<DataGrid.Columns>
<DataGridTextColumn Header="Id" Binding="{Binding Path=Id}" Width="80"/>





Arun Oli Selvan ManoharanPosted Apr 18, 2015, 2:17 AM
Hai.... kindly suggest how to print this datagrid with the images in wpf
edo wongPosted Jan 23, 2014, 5:56 AM
hello, I would like to know how to clear dbset/context data?