How can I bind data in xaml? I’m using the following logic:
SqlConnection conn = new SqlConnection("Data Source=mahendra;Initial Catalog=Win8App;User ID=sa;Password=*******");
conn.Open();
SqlCommand cmd = new SqlCommand("select * from tbl_Registration", conn);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
DataTable dt = new DataTable();
sda.Fill(dt);
cmd.ExecuteNonQuery();
dataGrid1.ItemsSource = dt.DefaultView;
conn.Close();
My basic need is to show the same data as the gridview.
You don’t have to execute the command. The DataAdapter do it for you (in the ‘Fill’ method). To show your result you can use your DataTable as a source and set the Autopopulate colums to true in your DataGrid. I think you don’t need the DataSet.