Thursday, June 30, 2011

DataViews and Filter Expressions

Yesterday I helped a colleague with a problem involving a DataView that would not find any rows when given a valid filter expression that should have returned rows. It took a little while to figure the problem out, so I thought I’d post the solution in case anyone else is stuck with the same issue.

In our case we had a DataTable (as part of a DataSet) that contained rows. Using the Debug Visualiser for the DataSet we could view the rows and see the data we expected. We had a column called BranchId and we wanted to find rows with a specific value in this column. If we wrote our own loop (we’re working in .Net 2.0 so no LINQ etc.) to iterate all the rows, request the value of the BranchId column and check it against the value we were searching for (17 in the first case) we found the row no problem. However, if we created a DataView with a filter expression of “[BranchId] = 17” now rows were returned.

The usual culprit here is ‘RowState’, where you must tell the DataView whether to include added rows, deleted rows, or to look at the modified or original versions of the rows. However, our code was correctly telling the DataView which row states to check, and the row state for the rows in question matched, so this was not the problem. Interestingly if we called AcceptChanges on the DataSet then the view would work fine, but we couldn’t do this because we needed to retain the current row state value for later in our algorithm, and AcceptChanges resets the row state.

In the end it turned out the problem was caused by a failure to call ‘EndEdit’ on the row. Specifically, the BranchId value for these rows had been programmatically set via code earlier in the application and EndEdit hadn’t been called on the row afterwards. This meant the proposed value was 17, but the current and original values were‘unset’ (note, not actually null as requesting the original value threw an exception saying the value didn’t exist, even though nulls were allowed). Calling EndEdit on the row moved the value from ‘Proposed’ to the current value without affecting the RowState, and then the DataView filter worked fine.

Of course this all makes perfect sense when you think about it, and of course you should call EndEdit to commit changes to a DataRow when you’ve finished making them. The confusing issue in this case was that ONLY DataView was checking the ‘current’ value of the field. Everything else (the Debugger Visualiser and other debug tools, and any code we wrote to check the column value without specifying which value to check) was checking the proposed value by default. This made it appear like the DataView or filter expression was at fault, and there was no help, guidance or clear hint that the issue was caused by the same field having two different values simultaneously. Also, since most of our edits occur through controls like the DataGrid, EndEdit usually gets called for us by the control. It was only because we had (unusually) set the DataSet value programmatically that we needed to manually call EndEdit ourselves. Interestingly, there also doesn’t appear to be anyway to tell the DataView to check the proposed value rather than the current (committed) value.

So, moral of the story (and a good thing to remember anyway), always call EndEdit on your DataRows after you’ve programmatically made changes to them (and you want to keep/commit those changes in memory).

Friday, June 24, 2011

Windows 8 for software developers: the Longhorn dream reborn?

I really wish there would be a public anouncement from Microsoft themselves clarifying a few things, but at least this puts some of the recent rumours/leaks in a positive light (rather than all the drama and doomsaying that has been going on);

Windows 8 for software developers: the Longhorn dream reborn?

Tuesday, June 07, 2011

Why Apple Enthusiasts Are Wrong About Windows 8 - Techland -

Why Apple Enthusiasts Are Wrong About Windows 8 - Techland -

Will Microsoft Own the Web (Again) ?


Contentious title, I know, but that’s just to get you here. If you’re reading this, it worked.

With the recent news about Windows 8 from Microsoft, like many, I’ve been pondering their future. Since I work for a software development company heavily invested in Microsoft tools and technologies, my future is tied to theirs so this makes sense. It’s hard to know what Microsoft’s strategy is, or if they have one at all. Sometimes it looks like they’re doing new cool things (WP7), although uptake by the market doesn’t always follow. Other times it looks like the right hand isn’t talking to the left, or the whole company is in panic mode. Much has been written about how Microsoft is behind it’s competitors, or no longer relevant, how Ballmer is (allegedly) driving it under and so on. There have also been the debacles over the question of the future Silverlight and the use of the admittedly idiotic term “Native HTML” all of which have caused laughter from some sections of the industry. All this may or may not be true at present, but I’m wondering if there isn’t a secret plan that’s being missed by most. I wonder if perhaps those laughing should stop and think about this a little bit longer.

Microsoft could be said to have owned the web at one stage, Netscape/Mozilla created the first browser but Microsoft came out with IE and basically crushed them. Let’s not forget that Microsoft is generally pretty good at playing catch-up even when it’s later to the game, it is good and experienced at being the underdog. We can argue about which product was actually better, or whether the business practices employed by Microsoft were fair and so on, but in the end they had far more of the browser market than any other. Of course, while IE is still widely used today, other browsers are growing faster and have stolen a significant portion of that market share.

Combine that with the up take in portable devices, mostly Smartphones and tablets like the iPhone, iPad, and Android phones and tablets, and Microsoft seems to be fighting a losing battle. Are Windows 8 and IE 9 part of a plan to turn that around ? That might sound ridiculous, obviously Microsoft are going to release new products, obviously they’re supposed to be better than what came before, and obviously Microsoft hopes those products will save them. What I’m asking is are Windows 8 and IE 9 the first steps in a plan to create the web client platform of choice ?

Hardware acceleration in the browser (IE9), a (supposedly, depending on your personal taste) cool and striking new UI for Windows based on the already much lauded WP7 interface, and an OS designed to run across a variety of platforms and form factors ? HTML5 and JScript as the development tools of choice for Windows 8? What if “Native HTML" is supposed to mean “Native and HTML” or something similar ? Taking HTML5 and JScript seriously opens up a lot of applications to running on Windows 8 and being sold through the new Windows 8 app store that wouldn’t have been if it was native only. If Windows 8 actually provided additional capabilities for web applications, things that couldn’t be done on other platforms, then web developers (at least some of them) would get excited about that. All of a sudden we have a class of (good/excellent) web applications that either only work, or work best on Windows. What if the plan is to produce the killer client OS for using the web ?

You may be terrified by this concept, after all, many see the web as a place free of dominance by a single client platform and want it to remain that way. Or you might just hate the idea of Microsoft being the winner here. You may scoff. Who knows if Microsoft can actually pull this off (no doubt many would argue they can’t)… but what if Microsoft turned Windows into the iOS of the web ? What if you could get web and internet experiences like no other, but only on the Windows platform  and that platform ran on your smartphone, your tablet, your laptop, your TV ?

What if having the fastest or best standards support or whatever in a browser doesn’t matter because the web is no longer separate to your OS, constrained inside the browser ? Is this Microsoft’s answer to ChromeOS, albeit with a different view… instead of the browser being the operating system shell, the OS is a bigger, better browser ? What if the point here is not to kill non-web applications or move away from them, but to actually enable web based applications to compete with non-web applications on performance, beauty, offline support and general user experience ? What if Microsoft made Windows the coolest platform for consuming the web and internet (on any device) as Apple made the iPhone coolest smartphone ?

Ok, so Microsoft have been building the internet and the web into Windows in various ways for a while, this isn’t exactly a new concept. Security is also a problem that gets bigger the more you integrate the internet and web to the OS. Microsoft may or may not pull it off, and if they do it’s likely to be Windows 10 before we see the full fruits of this (possible) plan (if any). Just for a moment though, throw out any bias you might have and consider what the world would be like if Microsoft managed this feat. What would the world be like if no one wanted to access the web unless they were using Windows ? What if Microsoft owned the web again ?

Friday, June 03, 2011

Mobile Opportunity: Windows 8: The Beginning of the End of Windows

Check out the following blog post by Michael Mace on Windows 8 and the future of Microsoft. It is an an excellent article with an interesting and well thought out analysis of both the possible success and failure Windows 8 represents for Microsoft. There's even a warning for traditional web companies, the likes of Google and Facebook, should everything come together in Microsoft's favour.

Mobile Opportunity: Windows 8: The Beginning of the End of Windows