ado。net的事物BeginTransaction demo

var seqNoList = seqNos.SplitToList(",");            

var db = CreateDb();            

List<DBParameter> paraList = new List<DBParameter>();            

DBParameter para = null;             string strSql = string.Empty;

            try             {                 db.BeginTransaction();

                for (int i = 0; i < seqNoList.Count; i++)                 {                     strSql = "delete from Item_tBasicInfo where SeqNo = @SeqNo";

                    paraList = new List<DBParameter>();                     para = new DBParameter("SeqNo", DbDataType.Int64);                     para.Value = seqNoList[i].ToInt64();                     paraList.Add(para);

                    db.ExecuteNonQuery(strSql, paraList);                 }

                db.Commit();                 return true;             }             catch             {                 db.Rollback();                 throw;             }

posted @ 2013-06-06 11:26  赤狐(zcm123)  阅读(269)  评论(0编辑  收藏  举报