cdo*_*ner 12 c# linq asp.net gridview transactionscope
我正在从Gridview发送的事件中进行级联删除.删除在交易中.这是简化的代码:
protected void btnDeleteUser_Click(object sender, EventArgs e)
{
DataContext db;
db = new DataContext();
using (TransactionScope ts = new TransactionScope())
{
try
{
//delete some data
db.SubmitChanges();
ts.Complete();
}
catch (Exception ex)
{
// handle error
}
finally
{
db.Dispose();
BindGridView();
}
}
}
private void BindGridView()
{
DataContext db;
db = new DataContext();
GridView.DataSource = <my query>
GridView.DataBind(); <========Exception
db.Dispose();
}
Run Code Online (Sandbox Code Playgroud)
对网格的DataBind()方法的调用失败,出现此异常:"当前的TransactionScope已经完成." 为什么?
当然,TransactionScope在那时完成,它应该完成.当我删除TransactionScope时,它的工作原理.
Rob*_*vey 15
将BindGridView()移到事务范围之外.
using (TransactionScope ts = new TransactionScope())
{
try
{
//delete some data
db.SubmitChanges();
ts.Complete();
}
catch (Exception ex)
{
// handle error
}
finally
{
db.Dispose();
}
}
BindGridView();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
11146 次 |
最近记录: |