bindingsource filter 的大于等于小于等于某个字段如何写?
我是这样写的:
bindingsource.filter = "SampleCode <= " + "'" + endcode + "'" + " and " + "SampleCode >= " +  "'" + endcode + "'" ;
这样写筛选不出我想要的数据?请问应该怎么写?

解决方案 »

  1.   

    filter = "SampleCode <= '" + endcode + "' and SampleCode >= '" + endcode + "'" ;
    reflector看到
    internal string AnalizePattern(string pat)
            {
                int length = pat.Length;
                char[] destination = new char[length + 1];
                pat.CopyTo(0, destination, 0, length);
                destination[length] = '\0';
                string str = null;
                char[] chArray2 = new char[length + 1];
                int num3 = 0;
                int num4 = 0;
                int index = 0;
                while (index < length)
                {
                    if ((destination[index] == '*') || (destination[index] == '%'))
                    {
                        while (((destination[index] == '*') || (destination[index] == '%')) && (index < length))
                        {
                            index++;
                        }
                        if (((index < length) && (num3 > 0)) || (num4 >= 2))
                        {
                            throw new Exception("ExprException.InvalidPattern(pat);");
                        }
                        num4++;
                    }
                    else if (destination[index] == '[')
                    {
                        index++;
                        if (index >= length)
                        {
                            throw new Exception("ExprException.InvalidPattern(pat);");
                        }
                        chArray2[num3++] = destination[index++];
                        if (index >= length)
                        {
                            throw new Exception("ExprException.InvalidPattern(pat);");
                        }
                        if (destination[index] != ']')
                        {
                            throw new Exception("ExprException.InvalidPattern(pat);");
                        }
                        index++;
                    }
                    else
                    {
                        chArray2[num3++] = destination[index];
                        index++;
                    }
                }
                str = new string(chArray2, 0, num3);
                if (num4 == 0)
                {
                    kind = 4;
                    return str;
                }
                if (num3 > 0)
                {
                    if ((destination[0] == '*') || (destination[0] == '%'))
                    {
                        if ((destination[length - 1] == '*') || (destination[length - 1] == '%'))
                        {
                            kind = 3;
                            return str;
                        }
                        kind = 2;
                        return str;
                    }
                    kind = 1;
                    return str;
                }
                kind = 5;
                return str;
            }
      

  2.   

    不是字符类型吧,去掉'号...
    bindingsource.filter=string.Format("SampleCode <= {0} and SampleCode >= {0}",endcode);
      

  3.   

    应该是"Or",不是and。
    bindingsource.filter = "SampleCode <= " + "'" + endcode + "'" + " Or " + "SampleCode >= " + "'" + endcode + "'" ;
    逻辑搞错了
      

  4.   

    不过你的大于等于和小于等于怎么都是‘endcode’?应该是不同的吧,比如>=BeginCode <=endCode
    ,否则的话用'and'将筛选不出数据,用'or'将筛出全部数据,也就是无意义了。