/// <summary>
/// 批量删除时的辅助方法
/// </summary>
/// <param name="sKeys">值列表</param>
/// <param name="sbWhere">Sql in子句的参数</param>
/// <returns>in子句的参数与值</returns>
public List<SqlParameter> GetParaListByKeys(string sKeys, StringBuilder sbWhere)
{
string[] idList = sKeys.Split(',');
List<SqlParameter> lstPara = new List<SqlParameter>(idList.Length);
SqlParameter paraTemp = null;
string sPara = "";
for (int i = 0; i < idList.Length; i++)
{
sPara = string.Format("@s{0}", i);
sbWhere.Append(sPara);
if (i != (idList.Length - 1))
{
sbWhere.Append(",");
}
paraTemp = new SqlParameter(sPara, idList[i].ToUpper());
lstPara.Add(paraTemp);
}
return lstPara;
}
使用:
StringBuilder _sqlStr = new StringBuilder();
_sqlStr.Append("select * from tablename where columnName in({0})");
StringBuilder sbWhere = new StringBuilder();
List<SqlParameter> lstPara = dba.GetParaListByKeys(arrPeiZhiXiangID, sbWhere);
string sSql = string.Format(_sqlStr.ToString(), sbWhere.ToString());