六月婷婷综合激情-六月婷婷综合-六月婷婷在线观看-六月婷婷在线-亚洲黄色在线网站-亚洲黄色在线观看网站

明輝手游網(wǎng)中心:是一個免費提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺!

在ADO.NET中使用事務(wù)保護(hù)數(shù)據(jù)的完整性(4)

[摘要]實施事務(wù)既然我們已經(jīng)看了類和成員,讓我們來看一下基本的實施情況.接下來的代碼是一個簡單的情況,使用事務(wù)來保證兩個存儲過程-一個從表中刪除庫存,另一個增加庫存在另個表中,或同時執(zhí)行,或失敗.using System;using System.Drawing;using System.Collecti...
實施事務(wù)

既然我們已經(jīng)看了類和成員,讓我們來看一下基本的實施情況.接下來的代碼是一個簡單的情況,使用事務(wù)來保證兩個存儲過程-一個從表中刪除庫存,另一個增加庫存在另個表中,或同時執(zhí)行,或失敗.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;

…public void SPTransaction(int partID, int numberMoved, int siteID)
{
// Create and open the connection.
SqlConnection conn = new SqlConnection();
string connString = "Server=SqlInstance;Database=Test;"
+ "Integrated Security=SSPI";
conn.ConnectionString = connString;
conn.Open();

// Create the commands and related parameters.
// cmdDebit debits inventory from the WarehouseInventory
// table by calling the DebitWarehouseInventory
// stored procedure.
SqlCommand cmdDebit =
new SqlCommand("DebitWarehouseInventory", conn);
cmdDebit.CommandType = CommandType.StoredProcedure;
cmdDebit.Parameters.Add("@PartID", SqlDbType.Int, 0, "PartID");
cmdDebit.Parameters["@PartID"].Direction =
ParameterDirection.Input;
cmdDebit.Parameters.Add("@Debit", SqlDbType.Int, 0, "Quantity");
cmdDebit.Parameters["@Debit"].Direction =
ParameterDirection.Input;

// cmdCredit adds inventory to the SiteInventory
// table by calling the CreditSiteInventory
// stored procedure.
SqlCommand cmdCredit =
new SqlCommand("CreditSiteInventory", conn);
cmdCredit.CommandType = CommandType.StoredProcedure;
cmdCredit.Parameters.Add("@PartID", SqlDbType.Int, 0, "PartID");
cmdCredit.Parameters["@PartID"].Direction =
ParameterDirection.Input;
cmdCredit.Parameters.Add
("@Credit", SqlDbType.Int, 0, "Quantity");
cmdCredit.Parameters["@Credit"].Direction =
ParameterDirection.Input;
cmdCredit.Parameters.Add("@SiteID", SqlDbType.Int, 0, "SiteID");
cmdCredit.Parameters["@SiteID"].Direction =
ParameterDirection.Input;

// Begin the transaction and enlist the commands.
SqlTransaction tran = conn.BeginTransaction();
cmdDebit.Transaction = tran;
cmdCredit.Transaction = tran;

try
{
// Execute the commands.
cmdDebit.Parameters["@PartID"].Value = partID;
cmdDebit.Parameters["@Debit"].Value = numberMoved;
cmdDebit.ExecuteNonQuery();

cmdCredit.Parameters["@PartID"].Value = partID;
cmdCredit.Parameters["@Credit"].Value = numberMoved;
cmdCredit.Parameters["@SiteID"].Value = siteID;
cmdCredit.ExecuteNonQuery();

// Commit the transaction.
tran.Commit();
}
catch(SqlException ex)
{
// Roll back the transaction.
tran.Rollback();

// Additional error handling if needed.
}
finally
{
// Close the connection.
conn.Close();
}
}




// Commit the outer transaction.

tran.Commit();

}

catch(OleDbException ex)

{

//Roll back the transaction.

tran.Rollback();



//Additional error handling if needed.

}

finally

{

// Close the connection.

conn.Close();

}

}





主站蜘蛛池模板: 亚洲视频在线观 | 亚洲国产天堂在线观看 | 中文字幕一区婷婷久久 | 色视频在线观看免费 | 亚洲一区二区在线成人 | 欧美特黄一级片 | 五月激情网站 | 日本视频在线免费播放 | 日本a级片免费看 | 色狠狠综合| 日韩不卡视频在线 | 香蕉视频久久 | 天天做天天爱天天一爽一毛片 | 欧美午夜视频在线 | 色偷偷亚洲 | 日韩在线免费 | 亚洲图片综合 | 天天插天天狠 | 日本在线观看一区二区三区 | 亚洲第一综合网站 | 欧美中字| 最近中文字幕无吗高清免费视频 | 全黄a一级毛片 | 中文字幕日韩一区二区不卡 | 天天射天天干天天舔 | 亚洲视频免费在线播放 | 五月婷婷欧美 | 亚洲aa| 午夜在线观看免费 | 欧美视频一级 | 在线免费日韩 | 日韩另类| 日本在线免费看片 | 欧美专区在线播放 | 亚洲欧美日韩国产 | 偷拍精品视频一区二区三区 | 亚洲资源站| 亚洲欧美手机在线观看 | 在线不卡 | 日日视频 | 日日摸夜夜添欧美一区 |