3

So I tried to filter some rows out if a column is empty or null.
How do I do that?

It looks like I need some sort of SQL-Like statement.
I want something like:

t.DefaultView.RowFilter = string.Format("[disabilities] IS NOT NULL OR EMPTY");
2
  • What have you tried? What were the results? Commented Sep 24, 2018 at 19:50
  • @RyanWilson haven't try empty yet cos I dont know the syntax Commented Sep 24, 2018 at 19:53

1 Answer 1

5

As equivalent to String.IsNullOrEmpty in data table filter expression, you can use either of the following options:

  • dt.DefaultView.RowFilter = "ISNULL(ColumnName,'')=''"
  • dt.DefaultView.RowFilter = "LEN(ISNULL(ColumnName,''))=0"
  • dt.DefaultView.RowFilter = "ColumnName IS NULL OR ColumnName=''"

To make it !String.IsNullOrEmpty, you can use NOT(criteria) or use not equal operator <>:

  • dt.DefaultView.RowFilter = "NOT(ISNULL(ColumnName,'')='')"
  • dt.DefaultView.RowFilter = "NOT(LEN(ISNULL(ColumnName,''))=0)"
  • dt.DefaultView.RowFilter = "NOT(ColumnName IS NULL OR ColumnName='')"

For more information about filter expression syntax, take a look at DataColumn.Expression.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.