winfrom 在业务层实现事务控制的小例子

 更新时间:2020年6月25日 11:42  点击:2109

复制代码 代码如下:

try
    {
 using (TransactionScope tr = new TransactionScope())
 {
     int i = this.customermanager.addCustomer(customer);
     int j = this.homestatusmanager.updateHomestatus(homestatus);
     if ((i * j) > 0)
     {
  MessageBox.Show("记录插入成功!", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  Empty();
  tr.Complete();
     }
     else
     {
  MessageBox.Show("记录插入失败!联系管理员!", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  Empty();
     }
     tr.Dispose();
 }

    }
    catch(Exception err)
    {
 MessageBox.Show("记录插入失败" +err.ToString(), "消息", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }

[!--infotagslink--]

相关文章