using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data;
using System.Data.SqlClient;
namespace DataGridinXAMl
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : System.Windows.Window
{
public Window1()
{
InitializeComponent();
DataTable theTable = new DataTable();
// Setting the connection String
String connString = @"Data Source=MCN0100; Initial Catalog=DataBaseNew ;Integrated Security=True";
//Set the query
String query = @"SELECT ID, FirstName, LastName, Department,City,Country FROM Record";
// Fill the Set with the data
using (SqlConnection conn = new SqlConnection(connString))
{
//Passing the query and connection String
SqlDataAdapter da = new SqlDataAdapter(query, conn);
da.Fill(theTable);
//Making the object of DataGridView
System.Windows.Forms.DataGridView grid = this.FindName("gridView") as System.Windows.Forms.DataGridView;
//Set the source of DataGridView from where the data will come
grid.DataSource = theTable;
grid.Refresh();
}
// Set the Data Context
DataContext = theTable;
}
}
}
When user will run the application then all record will come in DataGridView of that table from which this DataGridView is connected.

Figure 1.