Simple Data Bindng of WPF DataGrid using SQL Server
B Sahoo Posted On : 09/05/2013
About Author
Biswaranjan Sahoo have good working and teching experience in Microsoft technology.

Simple Data Bindng of WPF DataGrid using SQL Server

Every Application has one motto i.e CURD operation. For retrieving data and display that in well formatted list is a common task and also main part of CURD operating.In a Windows application, we use the DataGridView for this task but in WPF, we have to use DataGrid. In this article, I will told you how we bind DataGrid with Sql server using WPF.

Before coming to my article, I want to give you a little knowledge regarding WPF. So it is better to understand the article and Code.


What is WPF

Windows Presentation Foundation (WPF) is  Computer Software graphical subsystem for rendering user interfaces in Windows-based applications .It  was initially released as part of .NET Framework 3.0. WPF uses DirectX. WPF attempts to provide a consistent programming model for building applications and separates the user interface from business logic.

Step By Step Guide for a Simple Data Bindng of WPF DataGrid Control

Step I

Create a table named as tblAddressInformation in Sql server Database.

CREATE TABLE tblAddressInformation (

      Id int IDENTITY(1,1) NOT NULL,

      FName nvarchar(50),
      LName nvarchar(50),

      MobileNo nvarchar(50),

      City nvarchar(50))

Step II

Create a new WPF Application using Visual studio 2010 Express .

Step III

Add  Sytem.Configuration reference to application.

Step IV

Add a new "Application Configuration File" with named "App.config" to application add write connectionString in App.config file.

Step V

Add a Grid Control from Toolbox to MainWindow.xaml an name as "grdAddress".

Step VI

Add namespaces to MainWindow.xaml.cs Page.

  1. System.Configuration
  2. System.Data
  3. System.Data.SqlClient

Create a function "datagridbind" with business logic. Create SqlConnection to retrieve data from database, fill with dataset and bind dataset/datatable with grdAddress. Call the datagridbind function by MainWindow()

Step VII

Apply some style to Grid control. Add DataGridTextColumn with Binding with Column name and set  their header.

Step VII

Now, time came to run the application and check the output.


Above these step, we have to follow to display data from Sql server in WCF DataGrid control.

The code is attached with this article. You can download the same.

Post your Suggetion or Comment
Name :
Email Address :
Comment :