日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

微軟企業庫中的事務處理

系統 1846 0

public bool Transfer( int transactionAmount, int sourceAccount, int destinationAccount)
{
bool result = false ;

// CreatetheDatabaseobject,usingthedefaultdatabaseservice.The
// defaultdatabaseserviceisdeterminedthroughconfiguration.
Databasedb = DatabaseFactory.CreateDatabase();

// Twooperations,onetocreditanaccount,andonetodebitanother
// account.
string sqlCommand = " CreditAccount " ;
DBCommandWrappercreditCommandWrapper
= db.GetStoredProcCommandWrapper(sqlCommand);

creditCommandWrapper.AddInParameter(
" @AccountID " ,DbType.Int32,sourceAccount);
creditCommandWrapper.AddInParameter(
" @Amount " ,DbType.Int32,transactionAmount);

sqlCommand
= " DebitAccount " ;
DBCommandWrapperdebitCommandWrapper
= db.GetStoredProcCommandWrapper(sqlCommand);

debitCommandWrapper.AddInParameter(
" @AccountID " ,DbType.Int32,destinationAccount);
debitCommandWrapper.AddInParameter(
" @Amount " ,DbType.Int32,transactionAmount);

using (IDbConnectionconnection = db.GetConnection())
{
connection.Open();
IDbTransactiontransaction
= connection.BeginTransaction();

try
{
// Creditthefirstaccount
db.ExecuteNonQuery(creditCommandWrapper,transaction);
// Debitthesecondaccount
db.ExecuteNonQuery(debitCommandWrapper,transaction);

// Committhetransaction
transaction.Commit();

result
= true ;
}

catch
{
// Rollbacktransaction
transaction.Rollback();
}

connection.Close();

return result;
}

在這段例子代碼中,其核心就是關于 IDbTransaction的使用。

微軟企業庫中的事務處理


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。?!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 永宁县| 泗洪县| 准格尔旗| 睢宁县| 运城市| 城固县| 芒康县| 青岛市| 广安市| 县级市| 南召县| 河曲县| 巨鹿县| 乃东县| 金湖县| 贵南县| 巢湖市| 四平市| 新邵县| 常州市| 淮北市| 云林县| 三江| 吉水县| 青神县| 蛟河市| 珲春市| 河池市| 恩平市| 三都| 绥江县| 永善县| 建始县| 潢川县| 厦门市| 贡嘎县| 疏附县| 定安县| 阜新市| 博湖县| 云梦县|