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();
            }
  • 相关阅读:
    解决运行docker命令要用sudo的问题
    python3 http.server 本地服务支持跨域
    Linux 命令速记本
    截取某段时间内的日志
    centos7 安装postgresql10
    centos 7 安装 mail
    centos7 mail
    centos7 mysql 5.7 官网下载tar安装
    修改storm ui 默认端口
    redis-trib构建集群
  • 原文地址:https://www.cnblogs.com/tiger8000/p/2201784.html
Copyright © 2011-2022 走看看