我有一个已经绑定到数据库的数据网格。单击按钮时如何在数据网格上显示数据?
这是我尝试过的...
private void button1_Click(object sender, RoutedEventArgs e)
{
SqlDataAdapter da = null;
DataSet ds = null;
try
{
da = new SqlDataAdapter("select * from Major", @"Data Source=Student;Initial Catalog=StudDB;Integrated Security=true;Persist Security Info=True;");
da.SelectCommand.CommandTimeout = 100000;
ds = new DataSet();
da.Fill(ds);
dataGrid1.ItemsSource = ds.Tables[0].DefaultView;
}
catch (SqlException ex)
{
throw ex;
}
}