private void button1_Click(object sender, RoutedEventArgs e)
{
DataTable dt = new DataTable();
string constring = "Data source=----------\\SQLEXPRESS;Initial Catalog=master;Integrated Security=True;";
using (SqlConnection con = new SqlConnection(constring))
{
con.Open();
string cmdstring = "select * from emp";
using (SqlCommand cmd = new SqlCommand(cmdstring, con))
using (SqlDataAdapter adp = new SqlDataAdapter(cmd))
adp.Fill(dt);
}
grid_emp.ItemsSource = dt.DefaultView;
}
when clicking on button output is looking like this..


Kiran Kumar TalikotiRank #814 · 2.8K reputationPosted Oct 17, 2013, 10:51 PM EDT
Make Autogeneratecolumns true in Xaml .
Posted Oct 17, 2013, 10:29 PM EDT
Posted Oct 18, 2013, 12:16 AM EDT
there are two conditions,
1)you have not set the Autogeneratecolumns property of gridview to true
2) if you have taken template columns int to the datagrid view set the bind path .
Hardik PatelRank #4,439 · 343 reputationPosted Oct 20, 2013, 10:05 PM EDT
in .xaml.cs