问题是 - 当我在datagrid中编辑某个时 - 它不会改变数据库中的任何内容。当我在数据库中添加另一个窗口新数据时 - 直到我重新启动程序才会显示新数据。如何将数据库添加到数据库并在datagrid中查看并更改数据网格中的数据并在数据库中更改? 我的teachertable.cs
public partial class TeachersTable : Window
{
public TeachersTable()
{
InitializeComponent();
}
CourseWorkFinal.University0DataSet university0DataSet;
CourseWorkFinal.University0DataSetTableAdapters.TeachersTableAdapter university0DataSetTeachersTableAdapter;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
university0DataSet = ((CourseWorkFinal.University0DataSet)(this.FindResource("university0DataSet")));
// Load data into the table Teachers. You can modify this code as needed.
university0DataSetTeachersTableAdapter = new CourseWorkFinal.University0DataSetTableAdapters.TeachersTableAdapter();
university0DataSetTeachersTableAdapter.Fill(university0DataSet.Teachers);
System.Windows.Data.CollectionViewSource teachersViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("teachersViewSource")));
teachersViewSource.View.MoveCurrentToFirst();
university0DataSet.Teachers.TeachersRowChanged += new University0DataSet.TeachersRowChangeEventHandler(Modify);
university0DataSet.Teachers.TeachersRowDeleted +=
new University0DataSet.TeachersRowChangeEventHandler(Modify);
}
void Modify(object sender, University0DataSet.TeachersRowChangeEvent e)
{
university0DataSetTeachersTableAdapter.Update(university0DataSet.Teachers);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
AddTeacher x = new AddTeacher();
x.Show();
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
university0DataSetTeachersTableAdapter.Update(university0DataSet.Teachers);
}