Prasanth R

Prasanth R

  • NA
  • 24
  • 45.9k

binding datagrid with wpf

Oct 18 2013 2:24 AM


here is the code

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..





Answers (4)