解决查询条件中in项目超过1000的情况(改用or)
核心处理方法如下:
int num = 0, pos = 0, startPos = 0; foreach (char c in tmpIn) { if (',' == c) num++; if ((num + 1) % 800 == 0 && c == ',') { ctrlIn = ctrlIn + inCode + " in ('" + tmpIn.Substring(startPos, pos - startPos).Replace(",", "','") + "' ) or "; startPos = pos + 1; } pos++; }
tmpIn:传入的in参数
CtrlIn为字符串" and ("
此种方法比较慢,一个字符一个字符的查找,找到逗号后,还要计算。。。
后改用此方法:
do { ctrlIn = ctrlIn + inCode + " in ('" + string.Join("','", mParam, startPos, sCount) + "' )or "; startPos = startPos + sCount; inLength = inLength - sCount; } while (inLength > sCount);