dataView.RowFilter = "id = 10"; // no special character in column name "id"
dataView.RowFilter = "$id = 10"; // no special character in column name "$id"
dataView.RowFilter = "[#id] = 10"; // special character "#" in column name "#id"
dataView.RowFilter = "[[id\]] = 10"; // special characters in column name "[id]"
dataView.RowFilter = "Name = 'John'" // string value
dataView.RowFilter = "Name = 'John ''A'''" // string with single quotes "John 'A'"
dataView.RowFilter = String.Format("Name = '{0}'", "John 'A'".Replace("'", "''"));
dataView.RowFilter = "Year = 2008" // integer value
dataView.RowFilter = "Price = 1199.9" // float value
dataView.RowFilter = String.Format(CultureInfo.InvariantCulture.NumberFormat,
"Price = {0}", 1199.9f);
dataView.RowFilter = "Date = #12/31/2008#" // date value (time is 00:00:00)
dataView.RowFilter = "Date = #2008-12-31#" // also this format is supported
dataView.RowFilter = "Date = #12/31/2008 16:44:58#" // date and time value
dataView.RowFilter = String.Format(CultureInfo.InvariantCulture.DateTimeFormat,
"Date = #{0}#", new DateTime(2008, 12, 31, 16, 44, 5);
dataView.RowFilter = "Date = '12/31/2008 16:44:58'" // if current culture is English
dataView.RowFilter = "Date = '31.12.2008 16:44:58'" // if current culture is German
dataView.RowFilter = "Price = '1199.90'" // if current culture is English
dataView.RowFilter = "Price = '1199,90'" // if current culture is German
dataView.RowFilter = "Num = 10" // number is equal to 10
dataView.RowFilter = "Date < #1/1/2008#" // date is less than 1/1/2008
dataView.RowFilter = "Name <> 'John'" // string is not equal to 'John'
dataView.RowFilter = "Name >= 'Jo'" // string comparison
dataView.RowFilter = "Id IN (1, 2, 3)" // integer values
dataView.RowFilter = "Price IN (1.0, 9.9, 11.5)" // float values
dataView.RowFilter = "Name IN ('John', 'Jim', 'Tom'" // string values
dataView.RowFilter = "Date IN (#12/31/2008#, #1/1/2009#)" // date time values
dataView.RowFilter = "Id NOT IN (1, 2, 3)" // values not from the list
dataView.RowFilter = "Name LIKE 'j*'" // values that start with 'j'
dataView.RowFilter = "Name LIKE '%jo%'" // values that contain 'jo'
dataView.RowFilter = "Name NOT LIKE 'j*'" // values that don't start with 'j'
dataView.RowFilter = "Name LIKE '[*]*'" // values that starts with '*'
dataView.RowFilter = "Name LIKE '[[]*'" // values that starts with '['
public static string EscapeLikeValue(string valueWithoutWildcards)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < valueWithoutWildcards.Length; i++)
{
char c = valueWithoutWildcards[i];
if (c == '*' || c == '%' || c == '[' || c == ']'
sb.Append("[").Append(c).Append("]");
else if (c == '\''
sb.Append("''");
else
sb.Append(c);
}
return sb.ToString();
}
// select all that starts with the value string (in this case with "*")
string value = "*";
// the dataView.RowFilter will be: "Name LIKE '[*]*'"
dataView.RowFilter = String.Format("Name LIKE '{0}*'", EscapeLikeValue(value));
/ operator AND has precedence over OR operator, parenthesis are needed
dataView.RowFilter = "City = 'Tokyo' AND (Age < 20 OR Age > 60)";
// following examples do the same
dataView.RowFilter = "City <> 'Tokyo' AND City <> 'Paris'";
dataView.RowFilter = "NOT City = 'Tokyo' AND NOT City = 'Paris'";
dataView.RowFilter = "NOT (City = 'Tokyo' OR City = 'Paris'";
dataView.RowFilter = "City NOT IN ('Tokyo', 'Paris'";
dataView.RowFilter = "MotherAge - Age < 20"; // people with young mother
dataView.RowFilter = "Age % 10 = 0"; // people with decennial birthday
// select people with above-average salary
dataView.RowFilter = "Salary > AVG(Salary)";
// select orders which have more than 5 items
dataView.RowFilter = "COUNT(Child.IdOrder) > 5";
// select orders which total price (sum of items prices) is greater or equal $500
dataView.RowFilter = "SUM(Child.Price) >= 500";
Copyright © 2024, NextGenUpdate.
All Rights Reserved.