WPF中的DataGrid控件中增加数据
private void DataGrid1_DataGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
{
Employee employee = e.Row.DataContext as Employee;
if (e.EditAction == DataGridEditAction.Commit)
{
using (CQDBEXT DB = new CQDBEXT())
{
Employee matchedData = DB.Employee.SingleOrDefault(zl => zl.id == employee.id);
if (matchedData == null)
{
matchedData = new Employee();
DB.InsertOnSubmit(matchedData);
}
matcheData.name = employee.name;
DB.SubmitChanges();
}
}
运行后在datagrid中的空行输入数据,总是提示不能访问已释放的对象,请问如何解决?