ASP.net(c#)+MySql 事务的使用方法

   public void getCheckListSubmit()
    {
        string _conStr = "................";//连接字符串
        OdbcConnection _odbcCon = new OdbcConnection(_conStr);
        _odbcCon.Open();

        OdbcTransaction trans = _odbcCon.BeginTransaction(IsolationLevel.ReadCommitted);
        OdbcCommand cmd = new OdbcCommand();
        cmd.Connection = trans.Connection;
        cmd.Transaction = trans;

        string sqlStr = "";
        try
        {
               sqlStr = ".................";

               cmd.CommandText = sqlStr;
              cmd.ExecuteNonQuery();

              sqlStr2 = ".................";
            cmd.CommandText = sqlStr2;
            cmd.ExecuteNonQuery();

                                         }
        catch
        {
            trans.Rollback();
            hidsysMsg.Value = "Insert Failed";
            _odbcCon.Close();
            return;
        }
        trans.Commit();
        hidsysMsg.Value = "Insert Succeeded";
        _odbcCon.Close();

    } 

ASP.net(c#)+MySql 事务的使用方法

展开阅读全文

没有更多推荐了,返回首页