数据库动态参数

StringBuilder sql = new StringBuilder();
List<MySqlParameter> ilistStr = new List<MySqlParameter>();
sql.Append("delete from activity_collection where UserCode=@UserCode and ( 1<>1 ");
for (int i = 0; i < idList.Count; i++)
{
sql.AppendFormat(" or id=@id{0}", i.ToString());
ilistStr.Add(new MySqlParameter("@id" + i.ToString(), idList[i]));
}
sql.Append(")");
ilistStr.Add(new MySqlParameter("@UserCode", userCode));
MySqlParameter[] param = ilistStr.ToArray();
int result = MySqlHelper.ExecuteNonQuery(sql.ToString(), param);
if (result > 0) {
return true;
}

posted @ 2016-08-17 17:08  haifeng_0712  阅读(180)  评论(0编辑  收藏  举报