日期:2014-05-17  浏览次数:20767 次

C#事务的问题,SqlTransaction 的对象,可以夸方法传递吗
   SqlConnection con = new SqlConnection(CommonERP.sqlConStr);
            //连接
            con.Open();
            //实例化事务
            SqlTransaction myst = con.BeginTransaction();
            try
            {
                //保存主表数据
                int mainResult = DAL.po_purchaseOrder.addPurchaseOrder(myst, obj);
                if (mainResult <= 0)
                {
                    myst.Rollback();
                    con.Close();
                }
                //循环保存子表数据
                for (int i = 0; i < rowAdd.Length; i++)
                {
                    //项次加1
                    string no = "0" + (maxNo += 1).ToString();
                    //构造正确项次
                    no = no.Substring(no.Length - 2);
                    //项次赋值
                    rowAdd[i]["poOrderItemNo"] = no;
                    int itemResult = DAL.po_purchaseOrder.addItem(myst, rowAdd[i], obj.PoOrderNo);