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

     using (SqlConnection connection = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))       

    {

     connection.Open();

    SqlCommand command = connection.CreateCommand();

    SqlTransaction transaction;           

    transaction = connection.BeginTransaction("SampleTransaction");           

    command.Connection = connection;           

    command.Transaction = transaction;

     try           

    {               

    command.CommandText = "Insert into Region (RegionID, RegionDescription) VALUES (100, ''Description'')";                command.ExecuteNonQuery();               

    command.CommandText = "Insert into Region (RegionID, RegionDescription) VALUES (101, ''Description'')";                command.ExecuteNonQuery();                // Attempt to commit the transaction.               

    transaction.Commit();                          

    }           

    catch (Exception ex)           

    {               

    try               

    {                   

    transaction.Rollback();               

    }               

    catch (Exception ex2)               

    {                   

    //Console.WriteLine("Rollback Exception Type: {0}", ex2.GetType());                   

    //Console.WriteLine("  Message: {0}", ex2.Message);               

    }           

    }       

    }

  • 相关阅读:
    中国式关系
    太太万岁
    matlab记录运行时间命令
    matlab读xls数据
    matlab,xls转换为mat文件
    matlab里plot设置线形和颜色
    matlab里plot画多幅图像、设置总标题、legend无边框
    matlab显示图像的横纵坐标
    去掉matlab图片空白边缘
    matlab显示原图和灰度直方图
  • 原文地址:https://www.cnblogs.com/mrray/p/2049632.html
Copyright © 2011-2022 走看看