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

微軟企業庫中的事務處理

系統 1738 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元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!?。?/p>

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 焦作市| 石城县| 炉霍县| 鸡泽县| 巧家县| 哈巴河县| 台南市| 绥棱县| 镇康县| 大渡口区| 德格县| 牟定县| 周口市| 益阳市| 临清市| 平潭县| 淳化县| 察雅县| 江永县| 郑州市| 广河县| 中山市| 江安县| 会昌县| 荥经县| 武邑县| 古交市| 滦南县| 溧阳市| 广安市| 瑞安市| 黄平县| 盘山县| 长汀县| 景洪市| 商城县| 宁安市| 沧州市| 天祝| 拉孜县| 永顺县|