zoukankan      html  css  js  c++  java
  • asp.net 事务回滚

          
            string getTitle = this.TextBox1.Text;
            string getAuthor = this.TextBox2.Text;
            string sql = "insert into 表(title,author) values ('" + getTitle + "','" + getAuthor + "'); select @@identity AS RID";

     
           //string sql = "insert into DepartMent(DepartMentName,DepartMentCode) values ('" + getName + "','" + getCode + "');insert into DepartMent(ID,DepartMentName) values ('"+@@identity +"','新部门测试')";
            string connStr = System.Configuration.ConfigurationManager.AppSettings["fff"].ToString();

            SqlConnection myconn = new SqlConnection(connStr);
            SqlCommand mycomm = new SqlCommand(sql,myconn);
            myconn.Open();
            SqlTransaction myTrans = myconn.BeginTransaction();
            mycomm.Transaction = myTrans;

            try
            {
                mycomm.ExecuteNonQuery();
                myTrans.Commit();
            }
            catch
            {
                myTrans.Rollback();
            }
            finally
            {
                myconn.Close();
            }
  • 相关阅读:
    javascript事件委托和jQuery事件绑定on、off 和one
    转:程序员面试、算法研究、编程艺术、红黑树、数据挖掘5大系列集锦
    网游加速器原理、技术与实现
    自动化测试等级
    游戏测试工具
    JMeter
    Python高级编程
    测试提高项目的方法
    python mysqldb
    Python中的操作符重载
  • 原文地址:https://www.cnblogs.com/tiger8000/p/2201784.html
Copyright © 2011-2022 走看看