WPF中的DataGrid控件中增加数据解决思路
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();还怎么提交修改啊???
皮之不存,毛将焉附!
------解决方案--------------------
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();还怎么提交修改啊???
皮之不存,毛将焉附!
------解决方案--------------------