Search code examples
c#datarowview

RowFilter LIKE operation


I know that the following is not allowed as a row filter

'canada%.txt' or 'canada*.txt'

and I guess I can rewrite my filter as

file_name like 'Canada%' and file_name like '%.txt' 

should work.

But is there an easier way instead of determing where the % is and spliting the string?


Solution

  • I don't believe that CHARINDEX is allowed in the filter expression.

    You might try to dynamically build the filter string from C# (very much untested, but here's a possible syntax):

    //split the original string using the wildcard as the delimiter
    string[] f = s.Split('%');
    
    //use the resulting array to build the resultstring
    string resultstring = 'file_name like "' + f[0] + '%" and file_name like "%' + f[1] + '"'
    
    //view.RowFilter = resultstring;