首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > CAD教程 >

WPF中的DataGrid控件中增加数据解决思路

2012-03-11 
WPF中的DataGrid控件中增加数据private void DataGrid1_DataGrid_RowEditEnding(object sender, DataGridR

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中的空行输入数据,总是提示不能访问已释放的对象,请问如何解决?
 
 


[解决办法]
当然了喽,你使用了
using (CQDBEXT DB = new CQDBEXT())
这样你在其范围外,该DB资源已经被释放掉了,你后面DB.SubmitChanges();还怎么提交修改啊???

皮之不存,毛将焉附!


[解决办法]

探讨
当然了喽,你使用了
using (CQDBEXT DB = new CQDBEXT())
这样你在其范围外,该DB资源已经被释放掉了,你后面DB.SubmitChanges();还怎么提交修改啊???

皮之不存,毛将焉附!

热点排行