• C# MVC EF框架 用事务


    using System.Transactions;

    [HttpPost]
    public JsonResult Update(InfoModel list)
    {
    using (TransactionScope transaction = new TransactionScope())
    {
    try
    {
    string sql = string.Format("update Member set M_Name='{0}', M_Pwd='{1}', M_Sex='{2}' where M_ID={3}", list.M_Name, list.M_Pwd, list.M_Sex, list.M_ID);
    string sql2 = string.Format("update Info set S_Hobbies='{0}', S_weight={1}, S_address='{2}' ,S_phone='{3}' where M_ID={4}", list.S_Hobbies, list.S_weight, list.S_address, list.S_phone, list.M_ID);
    var result1 = tc.Database.ExecuteSqlCommand(sql) > 0 ? true : false;
    var result2 = tc.Database.ExecuteSqlCommand(sql2) > 0 ? true : false;

    if (result1 && result2)
    {
    transaction.Complete();
    }
    }
    catch (Exception ex)
    {

    return Json(new { result = "1", message = "更新失败! "+ex });
    }

    }

    return Json(new { result = "0", message = "更新成功!" });
    }

  • 相关阅读:
    eclipse中包的位置
    404代码错误解决
    servlet-web.xml配置
    java web.xml配置servlet
    1031整理
    1030整理
    rownum
    存储过程和自定义函数的区别
    课堂整理
    练习
  • 原文地址:https://www.cnblogs.com/yyy116008/p/6802796.html
Copyright © 2020-2023  润新知