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

    string connString = WebConfigurationManager.ConnectionStrings"ConnectionString".ConnectionString;
    SqlConnection conn = new SqlConnection(connString);
    conn.Open();
    SqlTransaction tran = conn.BeginTransaction(); //创建事务Transaction
    
    string strSQL = "INSERT INTO Employees(FirstName, LastName, City, Address) values (@paramFirstName,@paramLastName,@paramCity,@paramAddress)";
    SqlCommand cmd = new SqlCommand(strSQL, conn,tran); //创建SqlCommand
    
    try
    {
    cmd.Parameters.Add("@paramFirstName", SqlDbType.NVarChar, 20).Value = txtFirstName.Text;
    cmd.Parameters.Add("@paramLastName", SqlDbType.NVarChar, 10).Value = txtLastName.Text;
    cmd.Parameters.Add("@paramCity", SqlDbType.NVarChar, 15).Value = txtCity.Text;
    cmd.Parameters.Add("@paramAddress", SqlDbType.NVarChar, 60).Value = txtAddress.Text;
    cmd.ExecuteNonQuery();
    tran.Commit(); //确认事务
    txtMsg.Text = "新增数据成功,事务确认!";
    }
    catch
    {
    tran.Rollback(); //事务回滚
    txtMsg.Text = "新增数据失败,事务Rollback!";
    }
    
    finally
    {
    conn.Close();
    conn.Dispose();
    tran.Dispose();
    cmd.Dispose();
    }
  • 相关阅读:
    js 正则表达式
    JAVA jdk环境搭建
    VMWareStation10 密钥
    linux xshell jdk hadoop(环境搭建) 虚拟机 安装(大数据搭建环境)
    linux hadoop jdk虚拟机下配置
    Linux shell基础(四)
    Linux shell基础(二)
    Linux shell基础(三)
    Linux shell基础(一)
    html
  • 原文地址:https://www.cnblogs.com/salmonwxs/p/13180661.html
Copyright © 2011-2022 走看看