DbHelperSQL 事務寫法!

來源:互聯網
上載者:User

標籤:

 1  try 2             {                3                 DBUtility.CommandInfo dbcom = new DBUtility.CommandInfo(); 4                 List<DBUtility.CommandInfo> strStranList = new List<DBUtility.CommandInfo>();              5  6                 StringBuilder strSql = new StringBuilder(); 7                 strSql.Append("Update Jia72_Members Set "); 8                 strSql.Append("[email protected],"); 9                 strSql.Append("[email protected],");10                 strSql.Append("[email protected],");11                 strSql.Append("[email protected],");12                 strSql.Append("[email protected],");13                 strSql.Append("[email protected],");14                 strSql.Append("[email protected],");15                 strSql.Append("[email protected]");16                 strSql.Append(" Where [email protected] ");17                 string strSQLM = strSql.ToString();18 19                 SqlParameter[] parameters = {20                     new SqlParameter("@Id",SqlDbType.Int,4),                    21                     new SqlParameter("@UserName",SqlDbType.NVarChar,20),22                     new SqlParameter("@YTCardId",SqlDbType.Int,4),23                     new SqlParameter("@CardNum",SqlDbType.NVarChar,20),24                     new SqlParameter("@Bank",SqlDbType.NVarChar,50),25                     new SqlParameter("@BankNumber",SqlDbType.NVarChar,32),                    26                     new SqlParameter("@QQNumber",SqlDbType.NVarChar,50),27                     new SqlParameter("@RealName",SqlDbType.NVarChar,10),            28                     new SqlParameter("@SavedOn",SqlDbType.DateTime)29                      };30                 parameters[0].Value = model.Id;31                 parameters[1].Value = model.UserName;32                 parameters[2].Value = model.YTCardId;33                 parameters[3].Value = model.CardNum;34                 parameters[4].Value = model.Bank;35                 parameters[5].Value = model.BankNumber;36                 parameters[6].Value = model.QQNumber;37                 parameters[7].Value = model.RealName;38                 parameters[8].Value = model.SavedOn;39 40                 dbcom.CommandText = strSql.ToString();41                 dbcom.Parameters = parameters;42                 strStranList.Add(dbcom);//綁定會員資訊              43 44                 //更新卡表45                 strSql.Clear();46                 strSql.Append("update Jia72_YTCard set ");47                 strSql.Append("IsBind=1,");48                 strSql.Append("SavedOn=getdate()");49                 strSql.Append(" where Id=" + model.YTCardId);50 51                 dbcom.CommandText = strSql.ToString();52                 dbcom.Parameters = null;53                 strStranList.Add(dbcom);//更新卡表綁定            54 55                 if (DBUtility.DbHelperSQL.ExecuteSqlTran(strStranList) > 0)56                 {57                     DotNet.Common.MessageBox.ShowAndRedirect(this, "儲存成功!", "UserManages.aspx");58                 }59                 else60                 {61                     MessageBox.Show(this, "操作失敗,請聯絡管理員!");62                 }63             }64             catch (Exception ex)65             {66                 LogHelper.WriteWebExLogInfo(this, ex);67                 MessageBox.Show(this, "操作失敗,請聯絡管理員!");68                 return;69             }

說明:引用 DBUtility 用CommandInfo組織參數!還得用SQLHelper,悲催呀!

DbHelperSQL 事務寫法!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.