第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

net事物提交的問題 大俠們過來看看 急??

net事物提交的問題 大俠們過來看看 急??

烙印99 2018-12-06 13:41:07
for (int i = 0; i < Parameter.Count; i++) { flag[i] = Commit.Commit.executeTransaction(sql[i], (SqlParameter[])Parameter[i]); } public static bool executeTransaction(string strSql, SqlParameter[] values) { bool flag = false; SqlCommand cmd = new SqlCommand(); cmd.Connection = _con;//命令對(duì)象 SqlTransaction myTransaction;//聲明一個(gè)SQL事物類型 myTransaction = con.BeginTransaction();//基于一個(gè)連接初始化事物 try { cmd.Transaction = myTransaction;//指定SQL命令語句 的事物 cmd.CommandText = strSql;//給定命令語句 if (values!= null) { foreach (SqlParameter parameter in values) { if ((parameter.Direction == ParameterDirection.InputOutput || parameter.Direction == ParameterDirection.Input) &&(parameter.Value == null)) { parameter.Value = DBNull.Value; } cmd.Parameters.Add(parameter); } cmd.ExecuteNonQuery();//執(zhí)行SQL語句 } flag = true; } catch (Exception ex) { flag = false; throw ex; } finally { _con.Close(); } return flag; } 我先得到所有的sql語句執(zhí)行的true 和false 當(dāng)全部是true的時(shí)候提交 代碼: Commit.Commit.executeTransaction(flag); 我這樣寫代碼行嗎? public static bool executeTransaction(bool[] flag) { int i = 0; bool sp = false; SqlCommand cmd = new SqlCommand(); cmd.Connection = _con;//命令對(duì)象 SqlTransaction myTransaction;//聲明一個(gè)SQL事物類型 myTransaction = con.BeginTransaction();//基于一個(gè)連接初始化事物 try { foreach (bool item in flag) { if (item == true) { i++; } else { i--; } } if (i == 4) { sp = true; myTransaction.Commit(); } else { myTransaction.Rollback(); } } catch (Exception ex) { sp = false; throw ex; } finally { _con.Close(); } return sp; } 我只要flag里面全部是 true就提交 不要執(zhí)行什么語句?但是當(dāng)全部是true的時(shí)候我看數(shù)據(jù)庫沒有數(shù)據(jù)?
查看完整描述

1 回答

?
翻閱古今

TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超5個(gè)贊

Transaction 得放到

for (int i = 0; i < Parameter.Count; i++)
??????????? {
??????????????? flag[i]
= Commit.Commit.executeTransaction(sql[i], (SqlParameter[])Parameter[i]);
??????????? }

之外,也就是說你所有執(zhí)行查詢的語句要使用同一個(gè) Transaction 對(duì)象。

查看完整回答
反對(duì) 回復(fù) 2019-01-21
  • 1 回答
  • 0 關(guān)注
  • 380 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)