我有一個已經綁定到數據庫的數據網格。 單擊按鈕時如何在數據網格上顯示數據?單擊按鈕時顯示數據網格
這裏是我已經試過......
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;
}
}
請張貼一些代碼,你到目前爲止已經試過... –
顯示一些代碼,請 –
請查一下我的問題的變化 – user1221765