DbHelperSQL 事务写法!

 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("UserName=@UserName,");
 9                 strSql.Append("YTCardId=@YTCardId,");
10                 strSql.Append("CardNum=@CardNum,");
11                 strSql.Append("Bank=@Bank,");
12                 strSql.Append("BankNumber=@BankNumber,");
13                 strSql.Append("QQNumber=@QQNumber,");
14                 strSql.Append("RealName=@RealName,");
15                 strSql.Append("SavedOn=@SavedOn");
16                 strSql.Append(" Where Id=@Id ");
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                 else
60                 {
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,悲催呀!

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。