Sql 的 in 查询,把list-string 改成 list - str 模式,以便可以做分组in查询
2017-11-23 17:18:55 访问(2638) 赞(0) 踩(0)
/// <summary>
/// Sql 的 in 查询,把list-string 改成 list - str 模式,以便可以做分组in查询
/// </summary>
/// <param name="theList"></param>
/// <returns></returns>
protected List<string> WhereAddSqlIn6ListString2Str
(
List<string> theList
)
{
int iCount = theList.Count;
if (iCount == 0)
{
throw new Exception
(
"方法:"
+ MethodBase.GetCurrentMethod().ReflectedType.FullName
+ " "
+ MethodBase.GetCurrentMethod().ToString()
+ " 发生异常:"
+ "传入的字符串参数:"
+ "List<int> theList"
+ "为null或为空。"
);
}
List<string> theResult = new List<string>();
int pageSize = MaxSqlInNum;
StringBuilder sbIds = null;
bool isFirst = true;
int addIdx = 0;
for (int i = 0; i < iCount; ++i)
{
// 空字符过滤 //
if (theList[i] == null || theList[i].Length == 0)
continue;
if (isFirst)
{
sbIds = new StringBuilder();
isFirst = false;
}
else {
sbIds.Append(",");
}
sbIds.Append(theList[i].Replace("'", "''"));
++addIdx;
if (addIdx == pageSize)
{
addIdx = 0;
isFirst = true;
theResult.Add(sbIds.ToString());
// 主动销毁资源,虽然意义不大 //
sbIds = null;
}
}
if (!isFirst)
{
if (sbIds != null)
{
theResult.Add(sbIds.ToString());
sbIds = null;
}
}
return theResult;
}
上一条:
下一条:
相关评论
发表评论