WinForm中是不是不支持like '_'的写法啊?
如下的语句,在SQL的查询分析器里能通过,在C#中,选出的记录却为0,为什么?ds.Tables["Base_Unit"].DefaultView.RowFilter = "Path like '________/00000033/%'";

解决方案 »

  1.   

    我的测试代码是这样的:
    DataTable dt1 = new DataTable();
    dt1.Columns.Add("number ", typeof(int));
    dt1.Columns.Add("Name", typeof(string));
    dt1.Columns.Add("age", typeof(int));
    dt1.Columns.Add("sex", typeof(string));dt1.Rows.Add(101,"张三", 12,"男");
    dt1.Rows.Add(102, "________/00000033/李四", 13, "男");
    dt1.Rows.Add(103, "王五", 14, "男");
    dt1.Rows.Add(104, DBNull.Value, null);
    dt1.Rows.Add(105, null, null);
    dt1.DefaultView.RowFilter = "name like '________/00000033/%'";
    Console.WriteLine(dt1.DefaultView.Count);
      

  2.   

    不是这个意思啊,"_"是用来表示任意的字符,比如说用name like '_bc' 可以找到name='abc'的记录~
      

  3.   

    RowFilter的表达式,并不是标准的Sql语法,而是C#的标准。好像没有单字符匹配。
      

  4.   

    字符串运算符 若要连接字符串,请使用 + 字符。DataSet 类的 CaseSensitive 属性的值确定字符串比较是否区分大小写。但是,可以用 DataTable 类的 CaseSensitive 属性重写该值。通配符 在 LIKE 比较中,* 和 % 两者可以互换地作为通配符。如果 LIKE 子句中的字符串包含 * 或 %,那么这些字符应用中括号([])对其进行转义。如果子句中有中括号,那么中括号字符应用中括号对其进行转义(例如 [[] 或 []])。在模式的开头和结尾,或者在模式的结尾,或在模式的开头,都允许使用通配符。例如: "ItemName LIKE '*product*'" "ItemName LIKE '*product'" "ItemName LIKE 'product*'" 在字符串的中间不允许使用通配符。例如,不允许 'te*xt'。
      

  5.   

    like 的模式用 ? 和 *