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

明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

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

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

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

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();

}

}





主站蜘蛛池模板: 日韩三级毛片 | 天天干 夜夜操 | 小黄鸭b站视频 | 亚洲精品青青草原avav久久qv | 色涩综合| 日本成人福利视频 | 在线观看视频中文字幕 | 日韩一级片在线播放 | 亚洲 自拍 欧美 综合 | 在线资源天堂 | 日本成人网址 | 午夜看片网站 | 色噜噜狠狠色综合中文字幕 | 中文字幕在线免费观看视频 | 性欧美暴力猛交69hd | 又爽又黄又无遮挡的视频在线观看 | 亚洲 欧美 国产 中文 | 青青青手机视频在线观看 | 亚州激情视频在线播放 | 亚洲一区二区三区免费在线观看 | 亚洲欧美香蕉在线日韩精选 | 日韩福利视频精品专区 | 香蕉狠狠干 | 亚洲天堂男人在线 | 日本欧美一区二区三区高清 | 天天想天天干 | 天堂中文在线网 | 日韩不卡高清 | 任我爽精品视频在线播放 | 四虎永久在线观看 | 四虎国产永久在线精品免费观看 | 啪啪网站免费看 | 特a级片| 色婷婷激婷婷深爱五月小说 | 婷婷狠狠五月天小说免费 | 亚洲伦理在线观看 | 青娱乐在线视频观看 | 日本xxx在线观看免费播放 | 亚洲综合色区中文字幕 | 中文字幕免费在线观看 | 一区小说二区另类小说三区图 |