1

I have a method that gets a list of numbers and filters my datatable according to it.

I use this code:

string MyQuery = CreateQueryMethod(MyNumbersList);
MyDataTable.DefaultView.RowFilter = MyQuery;

But if I get an empty list, MyQuery is just: "" // (string.empty) and if RowFilter is an empty string it shows the entire datatable - not filtered at all.

I want the datatable to be filtered to nothing in this case (I don't want to see any rows) what do I give RowFilter in order to get an empty datatable?

Ralf de Kleine
  • 11,464
  • 5
  • 45
  • 87
Johnny
  • 21
  • 1
  • 2

2 Answers2

2

You can put a filter that is always false (e.g. column1 != column1).

Itay Karo
  • 17,924
  • 4
  • 40
  • 58
2

Here is some code I use to filter a dataTable and transform the filtered results back to a table...

 DataTable Table = (Loaded from database)
 DataView view = Table.DefaultView;
 view.RowFilter = string.Format("ColumnName={0}", numericValue);
 DataTable FilteredTable = view.ToTable();
Gary Kindel
  • 17,071
  • 7
  • 49
  • 66