标题:c#事务回滚!
只看楼主
wasdwasd0302
Rank: 1
等 级:新手上路
帖 子:7
专家分:5
注 册:2013-5-13
结帖率:100%
已结贴  问题点数:10 回复次数:1 
c#事务回滚!
protected void btnUp_Click(object sender, EventArgs e)
        {
            bool b = Upload(FileUpload1);
            if (!b)
            {
                return;
            }
            string name = FileUpload1.FileName;
            string filepath = Server.MapPath("~/upload/") + name;
            Pf.CheckTable(Ds, "datetable");
            Ds = Db.GotData1("select * from [" + Db.DtName(filepath).Rows[0][2].ToString() + "]", "datetable1", Ds, filepath);

            OleDbConnection conn = Db.OpenConn();
            OleDbCommand oledbInsertCommand = conn.CreateCommand();
            oledbInsertCommand.Transaction = conn.BeginTransaction();
            try
            {
                foreach (DataRow dr in Ds.Tables["datetable1"].Rows)
                {
                    ......
                    string insertsql = "insert into Fee
                    Db.UpdateData(insertsql);
                    LblMsg.Text = "费用数据导入成功!";
                }
                ();
            }
            catch (Exception e1)
            {
                myTrans.Rollback();
                LblMsg.Text = e1.Message + "请确认文件内容无误!";
            }
            finally
            {
                conn.Close();
                myTrans.Dispose();
                conn.Dispose();  
            }
        }

 以上是代码的主要部分,通过读excel中的数据逐行往数据库里插入数据,我这边想实现如果中途出现导入异常的话,能够回滚到导入前的状态,而不是仅导入部分数据。我的这个为什么不行呢,从网上找的方法!
搜索更多相关主题的帖子: void return 
2013-05-27 16:15
wzz119
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:62
专家分:136
注 册:2013-1-7
得分:10 
帮顶    弱弱的问  能来个循环 + clear() 么.....
2013-05-28 14:47



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-408887-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.639352 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved