標籤:
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 事務寫法!