首页 > 其他 > 详细

C# 数据回滚

时间:2014-08-07 18:21:10      阅读:347      评论:0      收藏:0      [点我收藏+]
public  int GetExecteQuery(string strAddSql, string strUpdateSql, string strDelSql)
        {
            SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["GPSP_SQL"]);//实例化数据连接
            //SqlConnection conn = new SqlConnection(CONN_STRING);
            conn.Open();
            SqlCommand command = conn.CreateCommand();

            SqlTransaction transaction = null;
            transaction = conn.BeginTransaction();
            command.Connection = conn;
            command.Transaction = transaction;
            int count = 0;

            try
            {
                if (strAddSql != "")
                {
                    command.CommandText = “insert into A.....”;
                    command.ExecuteNonQuery();
                }
                if (strUpdateSql != "")
                {
                    command.CommandText = “insert into B.....”;
                    count = command.ExecuteNonQuery();
                }
                if (strDelSql != "")
                {
                    command.CommandText = “insert into C.....”;
                    count = command.ExecuteNonQuery();
                }
                transaction.Commit();
            }
            catch
            {

                transaction.Rollback();
            }

            return count;
        }

 

C# 数据回滚,布布扣,bubuko.com

C# 数据回滚

原文:http://www.cnblogs.com/beeone/p/3897555.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!