⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 asptransaction.aspx

📁 asp.net技术内幕的书配源码
💻 ASPX
字号:
<%@ Page Language="C#" Transaction="RequiresNew" %>
<%@ Import Namespace="System.EnterpriseServices" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script runat=server>
void Page_Load(Object sender , EventArgs e) 
{
 SqlConnection conBank;
 string  strUpdateAccountA;
 string  strUpdateAccountB;
 SqlCommand cmdUpdateAccountA;
 SqlCommand cmdUpdateAccountB;

// Initialize objects
conBank = new SqlConnection(@"Server=localhost;Trusted_Connection=true;database=conBank" );

strUpdateAccountA = "Update AccountA set { Balance = Balance - 999.99 WHERE Customer=//Smith//";
cmdUpdateAccountA = new SqlCommand( strUpdateAccountA, conBank );

strUpdateAccountB = "Update AccountB set { Balance = Balance + 999.99 WHERE Customer=//Smith//";
cmdUpdateAccountB = new SqlCommand( strUpdateAccountB, conBank );

// Open connection
conBank.Open();

// try executing both commands
try 
{
  cmdUpdateAccountA.ExecuteNonQuery();
  cmdUpdateAccountB.ExecuteNonQuery();

  // Commit the transaction
  ContextUtil.SetComplete();
  Response.Write( "Transaction Successful!" );
} 
catch (Exception eX) 
{
  ContextUtil.SetAbort();
  Response.Write( "Transaction Failed!" );
}

finally
{
  conBank.Close();
}
}

</script>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -