62,040
社区成员
发帖
与我相关
我的任务
分享
public bool Update(product model)
{
Hashtable htSyn = Hashtable.Synchronized(new Hashtable());
StringBuilder strSql = new StringBuilder();
strSql.Append("update product set ");
strSql.Append("productName=@productName,");
strSql.Append("Price=@Price,");
strSql.Append("pInfo=@pInfo,");
strSql.Append("pClassId=@pClassId,");
strSql.Append("pTitle=@pTitle,");
strSql.Append("pKey=@pKey,");
strSql.Append("pDescription=@pDescription,");
strSql.Append("pButtom=@pButtom,");
strSql.Append("isCan=@isCan,");
strSql.Append("isBast=@isBast,");
strSql.Append("IsNew=@IsNew,");
strSql.Append("isIndex=@isIndex,");
strSql.Append("pDate=@pDate,");
strSql.Append("eDate=@eDate,");
strSql.Append("pSourse=@pSourse,");
strSql.Append("ptag=@ptag,");
strSql.Append("pSort=@pSort,");
strSql.Append("Views=@Views");
strSql.Append(" where productId=@productId ");
htSyn.Add("@productName", model.productName);
htSyn.Add("@Price", model.Price);
htSyn.Add("@pInfo", model.pInfo);
htSyn.Add("@pClassId", model.pClassId);
htSyn.Add("@pTitle", model.pTitle);
htSyn.Add("@pKey", model.pKey);
htSyn.Add("@pDescription", model.pDescription);
htSyn.Add("@pButtom", model.pButtom);
htSyn.Add("@isCan", model.isCan);
htSyn.Add("@isBast", model.isBast);
htSyn.Add("@IsNew", model.IsNew);
htSyn.Add("@isIndex", model.isIndex);
htSyn.Add("@pDate", model.pDate);
htSyn.Add("@eDate", model.eDate);
htSyn.Add("@pSourse", model.pSourse);
htSyn.Add("@ptag", model.ptag);
htSyn.Add("@pSort", model.pSort);
htSyn.Add("@Views", model.Views);
htSyn.Add("@productId", model.productId);
if (db.ExecuteNonQuery(strSql.ToString(),htSyn) > 0)
{
return true;
}
return false;
}
ExecuteNonQuery里面的方法如下
using (SqlConnection conn = new SqlConnection(GetConnString()))
{
conn.Open();
SqlTransaction trans = conn.BeginTransaction();
try
{
SqlParameter[] param = new SqlParameter[ht.Count];
int i = 0;
foreach (DictionaryEntry objDE in ht)
{
param[i] = new SqlParameter(objDE.Key.ToString(), null);
param[i++].Value = objDE.Value;
}
SqlCommand comm = new SqlCommand(commandText, conn);
comm.Transaction = trans;
comm.Parameters.AddRange(param);
int val = comm.ExecuteNonQuery();
trans.Commit();
return val;
}
catch
{
trans.Rollback();
throw;
}
}
if(model.pDescription==null || model.pDescription=="" )
htSyn.Add("@pDescription", DBNull.Value);
else
htSyn.Add("@pDescription", model.pDescription);