{"id":9,"date":"2007-05-02T09:06:53","date_gmt":"2007-05-02T07:06:53","guid":{"rendered":"http:\/\/blog.eweibel.net\/?p=9"},"modified":"2009-02-03T11:22:37","modified_gmt":"2009-02-03T10:22:37","slug":"filtering-on-datatables","status":"publish","type":"post","link":"https:\/\/blog.eweibel.net\/?p=9","title":{"rendered":"Filtering on DataTables"},"content":{"rendered":"<p>When you want to apply a filter to your datatable in your dataset, you can use the method Select on the class DataTable. In our current project we use this method very often, also for databinding.<\/p>\n<p>Recently I discover an unexpected behaviour. Let\u2019s assume, that our datatable has 4 datarows and we will apply following filter for databinding:<br \/><font color=\"#000000\" size=\"2\">0=1 AND Path = &#8216;C:\\bin&#8217;<\/font><\/p>\n<p>The first expression (0=1) is added by an other method, which checks if any rows should be visible. The second expression (Path = \u2018C:\\bin\u2019) is the standard part of the filter (Yes, I know you could implement it much more simplier).<\/p>\n<p>Now, I programmed the following NUnit-Tests:<\/p>\n<p><font size=\"2\"><\/p>\n<p><\/font><font color=\"#008000\" size=\"2\">\/\/0=1 -&gt; OK<br \/><\/font><font color=\"#2b91af\" size=\"2\">DataRow<\/font><font size=\"2\">[] rowsComp = tabComp.Select(<\/font><font color=\"#a31515\" size=\"2\">&#8220;0=1&#8221;<\/font><font size=\"2\">);<br \/><\/font><font color=\"#2b91af\" size=\"2\">Assert<\/font><font size=\"2\">.IsNotNull(rowsComp);<br \/><\/font><font color=\"#2b91af\" size=\"2\">Assert<\/font><font size=\"2\">.AreEqual(0, rowsComp.Length);<\/font><font size=\"2\"><\/p>\n<p><\/font><font color=\"#008000\" size=\"2\">\/\/Name = &#8216;Component 7&#8217; -&gt; OK<br \/><\/font><font size=\"2\">rowsComp = tabComp.Select(<\/font><font color=\"#a31515\" size=\"2\">&#8220;(Name = &#8216;Component 7&#8217;)&#8221;<\/font><font size=\"2\">);<br \/><\/font><font color=\"#2b91af\" size=\"2\">Assert<\/font><font size=\"2\">.IsNotNull(rowsComp);<br \/><\/font><font color=\"#2b91af\" size=\"2\">Assert<\/font><font size=\"2\">.AreEqual(0, rowsComp.Length);<\/p>\n<p><\/font><font color=\"#008000\" size=\"2\">\/\/Path -&gt; OK<br \/><\/font><font size=\"2\">rowsComp = tabComp.Select(<\/font><font color=\"#a31515\" size=\"2\">@&#8221;Path = &#8216;C:\\bin'&#8221;<\/font><font size=\"2\">);<br \/><\/font><font color=\"#2b91af\" size=\"2\">Assert<\/font><font size=\"2\">.IsNotNull(rowsComp);<br \/><\/font><font color=\"#2b91af\" size=\"2\">Assert<\/font><font size=\"2\">.AreEqual(4, rowsComp.Length);<\/p>\n<p><\/font><font color=\"#008000\" size=\"2\">\/\/0=1 and Path (with brackets) -&gt; OK<br \/><\/font><font size=\"2\">rowsComp = tabComp.Select(<\/font><font color=\"#a31515\" size=\"2\">@&#8221;((0=1) AND (Path = &#8216;C:\\bin&#8217;))&#8221;<\/font><font size=\"2\">);<br \/><\/font><font color=\"#2b91af\" size=\"2\">Assert<\/font><font size=\"2\">.IsNotNull(rowsComp);<br \/><\/font><font color=\"#2b91af\" size=\"2\">Assert<\/font><font size=\"2\">.AreEqual(0, rowsComp.Length);<\/p>\n<p><\/font><font color=\"#008000\" size=\"2\">\/\/Name = &#8216;Component 7&#8217; and Path (without brackets) -&gt; OK<br \/><\/font><font size=\"2\">rowsComp = tabComp.Select(<\/font><font color=\"#a31515\" size=\"2\">@&#8221;(Name=&#8217;Component 7&#8242;) AND (Path = &#8216;C:\\bin&#8217;)&#8221;<\/font><font size=\"2\">);<br \/><\/font><font color=\"#2b91af\" size=\"2\">Assert<\/font><font size=\"2\">.IsNotNull(rowsComp);<br \/><\/font><font color=\"#2b91af\" size=\"2\">Assert<\/font><font size=\"2\">.AreEqual(0, rowsComp.Length);<\/p>\n<p><\/font><font color=\"#008000\" size=\"2\">\/\/0=1 and Path (without any brackets) -&gt; OK<br \/><\/font><font size=\"2\">rowsComp = tabComp.Select(<\/font><font color=\"#a31515\" size=\"2\">@&#8221;0=1 AND Path = &#8216;C:\\bin'&#8221;<\/font><font size=\"2\">);<br \/><\/font><font color=\"#2b91af\" size=\"2\">Assert<\/font><font size=\"2\">.IsNotNull(rowsComp);<br \/><\/font><font color=\"#2b91af\" size=\"2\">Assert<\/font><font size=\"2\">.AreEqual(0, rowsComp.Length);<\/p>\n<p><\/font><font color=\"#008000\" size=\"2\">\/\/0=1 and Path (without outer brackets) -&gt; Unexpected behaviour<br \/><\/font><font size=\"2\">rowsComp = tabComp.Select(<\/font><font color=\"#a31515\" size=\"2\">@&#8221;(0=1) AND (Path = &#8216;C:\\bin&#8217;)&#8221;<\/font><font size=\"2\">);<br \/><\/font><font color=\"#2b91af\" size=\"2\">Assert<\/font><font size=\"2\">.IsNotNull(rowsComp);<br \/><\/font><font color=\"#2b91af\" size=\"2\">Assert<\/font><font size=\"2\">.AreEqual(0, rowsComp.Length);<\/p>\n<p><\/font><\/p>\n<p>Only the last test failed. If you add around the whole expression brackets, then it works fine. Obviously the Select-Methode has a problem with expressions which doesn\u2019t operate over a column. I didn\u2019t try other expressions, but my current workarounds are remove all brackets or add an additional bracket around the whole expression.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When you want to apply a filter to your datatable in your dataset, you can use the method Select on the class DataTable. In our current project we use this method very often, also for databinding. Recently I discover an unexpected behaviour. Let\u2019s assume, that our datatable has 4 datarows and we will apply following filter for databinding:0=1 AND Path = &#8216;C:\\bin&#8217; The first expression (0=1) is added by an other method, which checks if any rows should be visible&#8230;.<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/blog.eweibel.net\/?p=9\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[5],"tags":[],"class_list":["post-9","post","type-post","status-publish","format-standard","hentry","category-good-practices"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/plOV9-9","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":1132,"url":"https:\/\/blog.eweibel.net\/?p=1132","url_meta":{"origin":9,"position":0},"title":"DataSet and deleted rows","author":"Patrick","date":"31. Jan 2012","format":false,"excerpt":"Yes, I know, the DataSet isn't the leading edge technology, but as the company where I work currently, there are several companies who use DataSet as data access technology. Recently, I had to migrate the DataSet subclasses of the framework of my current employer to .NET 4.0 and add LINQ\u2026","rel":"","context":"In &quot;.NET&quot;","block_context":{"text":".NET","link":"https:\/\/blog.eweibel.net\/?cat=13"},"img":{"alt_text":"Pair of cubic eggs","src":"https:\/\/i0.wp.com\/blog.eweibel.net\/wp-content\/uploads\/Fotolia_23504153_S_thumb.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":43,"url":"https:\/\/blog.eweibel.net\/?p=43","url_meta":{"origin":9,"position":1},"title":"Eat your own dog food","author":"Patrick","date":"2. Mar 2009","format":false,"excerpt":"Recently I heard the expression \"eat your own dog food\" again. For a company which produce software for a customer it is very usefull to use the same technology or product in house. But this expression is also usefull in the daily business of a modern software developer. One big\u2026","rel":"","context":"In &quot;Good practices&quot;","block_context":{"text":"Good practices","link":"https:\/\/blog.eweibel.net\/?cat=5"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":303,"url":"https:\/\/blog.eweibel.net\/?p=303","url_meta":{"origin":9,"position":2},"title":"From NUnit to MSTest","author":"Patrick","date":"30. Jun 2009","format":false,"excerpt":"Last week I migrated several projects from NUnit to MSTest. The developers use the Developer version of Microsoft Visual Studio Team System, so they have integrated unit-test support for MSTest. In this post I show you all the problems and work I had to migrate the tests from NUnit to\u2026","rel":"","context":"In &quot;.NET&quot;","block_context":{"text":".NET","link":"https:\/\/blog.eweibel.net\/?cat=13"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":200,"url":"https:\/\/blog.eweibel.net\/?p=200","url_meta":{"origin":9,"position":3},"title":"How to structure code in an unit test","author":"Patrick","date":"14. Jun 2009","format":false,"excerpt":"When you create your unit tests for a method in the SUT (software under test) you will ask yourself how to structure the code in the test method.I saw two kind of syntaxes which help to structure the code in a unit test method (well, actually there are at least\u2026","rel":"","context":"In &quot;.NET&quot;","block_context":{"text":".NET","link":"https:\/\/blog.eweibel.net\/?cat=13"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":459,"url":"https:\/\/blog.eweibel.net\/?p=459","url_meta":{"origin":9,"position":4},"title":"Fail Fast principle","author":"Patrick","date":"22. Sep 2009","format":false,"excerpt":"Recently I received a NullReference-Exception when I called another method from a foreign component. Fortunately I had the source code of this component and I found the following code: [code language=\"csharp\"] public class AgeValidator { public Dictionary Config { get; set; } public bool Validate(int nAge) { int nMinAge =\u2026","rel":"","context":"In &quot;Good practices&quot;","block_context":{"text":"Good practices","link":"https:\/\/blog.eweibel.net\/?cat=5"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":745,"url":"https:\/\/blog.eweibel.net\/?p=745","url_meta":{"origin":9,"position":5},"title":"ConfORM &ndash; Another NHibernate mapping possibility","author":"Patrick","date":"1. Sep 2010","format":false,"excerpt":"I recently hold two presentations at the .Net User Group Bern (DNUG) with Ren\u00e9 Leupold about object relational mapping in the .Net world. We showed Entity Framework 4.0 and NHibernate. My part was NHibernate. You could download the slides and samples from the DNUG website. In the two presentations I\u2026","rel":"","context":"In &quot;.NET&quot;","block_context":{"text":".NET","link":"https:\/\/blog.eweibel.net\/?cat=13"},"img":{"alt_text":"ConfOrmBigTransparent","src":"https:\/\/i0.wp.com\/blog.eweibel.net\/wp-content\/uploads\/ConfOrmBigTransparent_thumb.png?resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/blog.eweibel.net\/index.php?rest_route=\/wp\/v2\/posts\/9","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.eweibel.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.eweibel.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.eweibel.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.eweibel.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9"}],"version-history":[{"count":1,"href":"https:\/\/blog.eweibel.net\/index.php?rest_route=\/wp\/v2\/posts\/9\/revisions"}],"predecessor-version":[{"id":33,"href":"https:\/\/blog.eweibel.net\/index.php?rest_route=\/wp\/v2\/posts\/9\/revisions\/33"}],"wp:attachment":[{"href":"https:\/\/blog.eweibel.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.eweibel.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.eweibel.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}