Posted By

rengber on 01/31/08


Tagged

data filter ADONet


Versions (?)

Filter Expression for a DataTable


 / Published in: C#
 

Pretty intuitive, might be an easier/simpler way.

  1. //This was the hard way.
  2. public static Lookup.StatusDataTable GetStatuses(bool intranetMode)
  3. {
  4. //TODO: Handle Intranet vs Internet mode.
  5. LookupTableAdapters.StatusTableAdapter sta = new LookupTableAdapters.StatusTableAdapter();
  6. Lookup.StatusDataTable sdt = sta.GetStatusData();
  7. DataRow[] rows = sdt.Select("Status <> 'Unapproved' and Status <> 'Closed'");
  8. Lookup.StatusDataTable retVal = new Lookup.StatusDataTable();
  9. foreach(DataRow dr in rows)
  10. {
  11. retVal.Rows.Add(dr.ItemArray);
  12. }
  13. return retVal;
  14. }
  15.  
  16. //Here's the easy way:
  17. public static Lookup.StatusDataTable GetStatuses(bool intranetMode)
  18. {
  19. LookupTableAdapters.StatusTableAdapter sta = new LookupTableAdapters.StatusTableAdapter();
  20. Lookup.StatusDataTable sdt = sta.GetStatusData();
  21. if (!intranetMode)
  22. {
  23. sdt.DefaultView.RowFilter = "Status <> 'Unapproved' and Status <> 'Closed'";
  24. }
  25. return sdt;
  26. }

Report this snippet  

You need to login to post a comment.