Monday, August 29, 2016

Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.

This one annoyed me enough to dust off the blog. I created a simple data-bound form in C# with Visual Studio 2015. It's just a grid bound to a data table and when I click a button, the data is saved. It's the "Hello World" of database applications just so I can key in some data easily.

Everything's working great. The app functions as it's supposed to doesn't. All of a sudden, I start to see this error "Concurrency violation: the UpdateCommand affected 0 of the expected 1 records." I google it and see folks talking about actual concurrency issues (not happening here, I'm the only one using the database) and even date/time settings. Nothing that would cause me to have this error message

Finally, I just fire up the SQL Profiler and trace what's happening behind the scenes. I can see the update statement that's sent by Entity Framework is doing an update with a condition where field_value = @original_field_value. That's it. The original field value was null and any test against null fails. It turns out that the original dataset was defined when the field wasn't nullable. When I updated the table to allow nulls, I never updated the dataset definition. Once I did that in the dataset editor, the update statement was modified automatically to handle null values correctly.

Friday, January 9, 2015

Thursday, January 8, 2015

Using font icons in Xamarin.Android

One technique that I've found to make great looking icons in mobile applications is using SVG icons. Sites like IcoMoon and FontAwesome provide free and premium icons packaged as SVG graphics or true type fonts. The advantages of these icons over PNG images is that they are by nature resolution independent. Instead of having to include multiple copies in your project at different DPI levels, you can include a small ttf file and have access to the images you need at any resolution.

For my project, I needed a check mark (available), an 'X' (unavailable), as well as icons for refresh and calendar. I wandered over to and selected the icons using the icomoon app. From there I was able to download a custom font that included the icons as well as a demo webpage showing the character strings necessary to render them.

With the font downloaded, I added it to my Xamarin.Android projects /Assets folder.

Looking at the HTML file included with the zip download, I could see that the characters for my icons are using ea0f and ea10 for unavailable and available respectively.

In my list row adapter in the Xamarin.Android project, I defined these characters in a dictionary.

Finally, when defining the layout for the row, I loaded the font and set the character text and color according to the data. Reserved rooms have a red X and available rooms have a green checkmark.

Note that the line that is setting the text to e953 displays the separate calendar icon.

The rendered list appears below (unfortunately, it was a busy day to use real data, so no available rooms are shown)

This is cross-posted from the Anexinet Mobility blog

Thursday, April 10, 2014

Custom Site Branding with XSLT and MVC

Frequently, the clients I build applications for request the ability to customize their sites for their own clients. In the past, this might be accomplished by selecting a different CSS stylesheet for each client. That has the unfortunate drawback of trying to maintain styles across multiple copies. Another approach would be to generate style information in the page itself, but this doesn't provide the benefit of caching style information on the client side.

The approach I'm using currently is parameterized XSL transforms that can generate a style sheet on the fly from a template via an MVC controller action.

After creating an empty MVC project and adding a HomeController and View/Home/Index.cs, I set up my layout as follows:

In this layout, I've split my stylesheets into two categories. Structure concerns itself with size and placement. Brand concerns itself with colors, but may also include typography.

The branding in this case isn't a CSS file, it's an XSLT file.

I've added parameters to the XSLT file that can be supplied at runtime to change the appearance. This content gets merged with the simple brand.xml in the controller.

The controller uses a customization class stored in the models folder. In this case, to simplify things, I'm hardcoding the values and basing the customization on host-headers. Feel free to pull the information from a database or base the customization on user role, etc.

Cross-posted from

Monday, January 13, 2014

Gaming the App Store

So it turns out that folks max out their app's price to $999.99 and have a 3rd party purchase copies until Apple considers them a "top paid" app. I'm sure that Apple recognizes this and does nothing because they're making a 30% profit in any case.

Wednesday, December 11, 2013

How to wrap your Macbook power adapter

This is simply genius. Finally a way to deal with that clumsy power adapter -